2014-03-31 85 views
1

我试图在表视图加载时选择一行。我发现其他线程关于这个问题,但他们没有解决我的问题,所以我再问。无法以编程方式选择UITableViewCell

我的tableview包含5行。而我这样做:

if ([[dataSource objectAtIndex:indexPath.row] isEqualToString:self.status]) { 
    [self tableView:[self tableView] didSelectRowAtIndexPath:indexPath]; 
} 

我也试过cell.selected = YES;cell.highlighted = YES;

我使用custion选择视图下面的代码:

UIView *customColorView = [[UIView alloc] init]; 

customColorView.backgroundColor = [UIColor colorWithRed:180/255.0 
                 green:138/255.0 
                 blue:171/255.0 
                 alpha:0.5]; 
cell.selectedBackgroundView = customColorView; 

请帮我编程选择行。当我点击该行时,该行被选中,但无法以编程方式选择。

+0

didSelectRowAtIndexPath是委托方法。 – Masa

回答

1

尝试表视图对象上调用selectRowAtIndexPath:

if ([[dataSource objectAtIndex:indexPath.row] isEqualToString:self.status]) 
{ 
    [self.tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone]; 
} 
3

尝试用下面的代码

[self.tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone]; 

在这里你需要设置indexPath为您要选择的行。

3

你可以通过调用UITableView委托方法是

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {} 

这个方法,你需要检查同一小区,你不被窃听每个选定的时间内得到这个。

if ([[myArray objectAtIndex:indexPath.row] isEqualToString:self.same]) 
{ 
    [myTable selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone]; 
} 
相关问题