Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I believe i understand what you are trying to do, you want to display different table view cells depending on which of the button segments is selected.</p> <p>You need to have your cellForRowAtIndexPath check which segment is selected and return the correct set of cells.</p> <p>When the user changes the segmented button, have changeSegment: store the selected segment in an instance variable. Then have it call [self reloadData];</p> <pre><code>#import "DetailViewController.h" @interface DetailViewController () { NSArray *names; NSInteger segIndex; } @property (nonatomic, strong) NSArray *names; @property (nonatomic) segIndex; @end @implementation DetailViewController @synthesize tblView; @synthesize names; @synthesize segIndex; - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self; } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view from its nib. //Customize tableview tblView = [[UITableView alloc] init]; self.names = [NSArray arrayWithObjects: [NSArray arrayWithObjects:@"Parth",@"Bhadresh",@"Marshal", nil], [NSArray arrayWithObjects:@"Dipakbhai",@"Dineshbhai",@"Mansukhbhai",nil], [NSArray arrayWithObjects:@"Patel",@"Laiya",@"Kaneria", nil], nil]; tblView.delegate = self; tblView.dataSource = self; } -(void)viewWillAppear:(BOOL)animated { sgmtControl.frame = CGRectMake(17, 180, 285, 44); tblView.frame = CGRectMake(0, 0, 320, 364); tblView.hidden = YES; [self.view addSubview:tblView]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return [self.names count]; } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [[self.names objectAtIndex:section] count]; } -(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection: (NSInteger)section { switch (section) { case 0: return @"FirstName"; case 1: return @"MiddleName"; case 2: return @"LastName"; } return nil; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *myIdentifier = @"MyIdentifier"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:myIdentifier]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:myIdentifier]; } cell.textLabel.text =[[self.names objectAtIndex:self.segIndex] objectAtIndex:indexPath.row]; return cell; } -(IBAction)changeSegement:(id)sender { self.segIndex = sgmtControl.selectedSegmentIndex; [self reloadData]; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload