I am working in UITableView and trying to let the user to select cells using this code
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSInteger row = [indexPath row];
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if(cell != nil)
{
if(cell.accessoryType == UITableViewCellAccessoryNone)
开发者_如何学编程 {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
else
{
cell.accessoryType = UITableViewCellAccessoryNone;
}
}
}
but the problem is when the cell count over one page if you select cell number 1 the row number 1 in each page will be selected too.
static NSString * cellIdentifier = @"CellIdentifier"
in this place use
NSString *CellIdentifier = [NSString stringWithFormat:@"Cell%i",indexPath.row];
Nice answer, you really helped put me on the right track.
My 2 cents to help somebody else:
I'm using a grouped table so I changed it up a bit to make it:
NSString *CellIdentifier = [NSString stringWithFormat:@"Cell%i-%i", indexPath.section, indexPath.row];
Hope this helps somebody else.
use this pass the global variable one class to other class or one view controller to a other view controller.
globalString=[Arrayname objectAtIndex:indexPath.row];
Write this code in tableviewdidselect delegate method.
精彩评论