i went table view change content depend on SegmentIndex
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
// Set up the cell
book *bok = (book *)[self.booktable objectAtIndex:indexPath.row];
NSArray *rowoftitle = [NSArray arrayWithObjects:bok.book_title, nil];
NSArray *rowofauth = [NSArray arrayWithObjects:bok.author_name, nil];
NSArray *rowofpub = [NSArray arrayWithObjects:bok.pub_name, nil];
//[cell setText:bok.book_title];
[tableView beginUpdates];
switch (segControl.selectedSegmentIndex)
{
case 0:
[tableView insertRowsAtIndexPaths:rowoftitle withRowAnimation:UITableViewRowAnimationTop];
//cell.textLabel.text =bok.book_title;
break;
case 1:
[tableView insertRowsAtIndexPaths:rowofauth withRowAnimation:UITableViewRowAnimationTop];
//[libraryTV reloadData];
//cell.textLabel.text =bok.author_name;
break;
case 2:
[tableView insertRowsAtIndexPaths:rowofpub withRowAnimation:UITableViewRowAnimationTop];
//cell.textLabel.text =bok.pub_name;
break;
default:
break;
}
[tableView endUpdates];
//return cell;
}
but when run it the expiation is happen :
‘NSInvalidArgumentException’, reason: ‘-[NSCFString row]: unrecognized
selector sent to instance 0x5d84f80
how resolve it.
One solution could be:
You will need to use a common datasource (in this code I am using
dataSourceArrayfor this purpose, you will need to declare it in header file and alloc/init inviewDidLoadmethod.), which will be updated on changing the segment.It will have following method.(for segment change event)
Similarly code for other methods
loadAuthorsandloadPublishers.Now your
numberOfRowsInSectionmethod will be:and
cellForRowAtIndexPathwill be:Thanks