Cocoa touch iOS uitableview单元格仅被选中一段时间
在我的代码中,我想在UITableView中选择一个单元格。我在这里执行选择,但每次应该选择它时,它只会被选中一小会儿,然后它就失去了选择 我做错了什么Cocoa touch iOS uitableview单元格仅被选中一段时间,cocoa-touch,ios5,Cocoa Touch,Ios5,在我的代码中,我想在UITableView中选择一个单元格。我在这里执行选择,但每次应该选择它时,它只会被选中一小会儿,然后它就失去了选择 我做错了什么 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView dequeueReusableCellWithIdenti
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SimpleTableIdentifier"];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"SimpleTableIdentifier"];
}
cell.textLabel.text = [[self tableViewArray] objectAtIndex:indexPath.row];
if(indexPath.row == self.selectedTopicIndex)
{
NSLog(@"DIE DIE DIE DIE DIE!!!");
[cell setSelected:YES];
[cell setSelectionStyle:UITableViewCellSelectionStyleBlue];
[cell setSelected:YES];
}
return cell;
}
只需将您的选择逻辑移动到
-tableView:willDisplayCell:forrowatinexpath:
方法中即可。
大概是这样的:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
if(indexPath.row == self.selectedTopicIndex)
{
NSLog(@"DIE DIE DIE DIE DIE!!!");
[cell setSelectionStyle:UITableViewCellSelectionStyleBlue];
[cell setSelected:YES];
}
}
您能否向我们展示您的
表格视图:didSelectRowAtIndexPath:
实现?