选中时,Xcode UITableView行未突出显示

时间:2012-04-02 10:49:43

标签: iphone objective-c xcode uitableview

我的iphone应用程序上有一个工作表视图,并使用navigationController实现第二个视图。

但是当我尝试在初始视图上选择一个单元格时,它没有响应,即没有蓝色突出显示,没有选择。

任何人都可以建议我可能错过的内容,或者当用户点击它时实际选择单元格的原因是什么?

好的,谢谢你的建议 - 仍然没有运气。这是我的代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]autorelease];

        [cell setSelectionStyle: UITableViewCellSelectionStyleBlue]; 

        UIView *selectionView = [[[UIView alloc] init] autorelease];
        selectionView.backgroundColor =[UIColor redColor];
        cell.selectedBackgroundView = selectionView;
    }

    // format text

    cell.textLabel.font = [UIFont fontWithName:@"Arial" size:12];
    cell.textLabel.text = [tableArray objectAtIndex:indexPath.row];

        return cell;
}


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

    //NSUInteger row = indexPath.row;
    //[DetailView selectRowAtIndexPath:indexPath animated:YES];

    //UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath.row];
    //[cell setSelectionStyle: UITableViewCellSelectionStyleBlue]; 


    DetailView *detailView = [[DetailView alloc] initWithNibName:@"DetailView" bundle:nil];
    [self.navigationController pushViewController:detailView animated:YES];
    [DetailView release];

}

2 个答案:

答案 0 :(得分:3)

如果不查看您的代码,我会说您必须在cellForRowAtIndexPath委托方法中添加此行。

 [cell setSelectionStyle:UITableViewCellSelectionStyleBlue];

而且你必须实现这个委托方法,当你点击UITableView的单元格时会调用它。

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


}

答案 1 :(得分:3)

您可能在cellForRowatIndexPath ::

中完成了这行代码
 cell.selectionStyle = UITableViewCellSelectionStyleNone;

如果是,则将其替换为以下任一项:

 cell.selectionStyle = UITableViewCellSelectionStyleGray;

 cell.selectionStyle = UITableViewCellSelectionStyleBlue;