iPhone Coding: Problem with UITableView selection
I have a strange problem with my UITableView. I want all the cells in the table to be selectable, such that if a cell is selected, an appropriate action is executed. All the cells in my table are c开发者_高级运维urrently selectable apart from the cell at row 0 (the cell at that appears at the top of the table). This cell is not selectable, even though it has been set to allow for selection. Any ideas?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
tableView.allowsSelection = YES;
static NSString *SettingsTableID = @"SettingsTableID";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SettingsTableID];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1
reuseIdentifier: SettingsTableID] autorelease];
}
cell.textLabel.text = [tableHeadingsArray objectAtIndex:row];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
Many thanks.
Sorry everyone, I'm being stupid. :) This code was in my ViewController sub-class. I copied the class from an example, and forgot to check it over thoroughly before using it.
-(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath{
NSUInteger row = [indexPath row];
if (row == 0)
return nil;
return indexPath;
}
Deleting this has fixed the problem.
Cheers.
精彩评论