iphone - 选择时 Xcode UITableView 行未突出显示

标签 iphone objective-c xcode uitableview

我的 iphone 应用程序上有一个工作 TableView ,我正在使用 navigationController 实现第二个 View 。

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

任何人都可以建议我可能遗漏了什么,或者当用户点击时实际选择单元格的负责人是什么?

好的,谢谢你的建议 - 还是不行。这是我的代码:

- (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];

}

最佳答案

可能是您在 cellForRowatIndexPath::

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

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

 cell.selectionStyle = UITableViewCellSelectionStyleGray;

 cell.selectionStyle = UITableViewCellSelectionStyleBlue;

关于iphone - 选择时 Xcode UITableView 行未突出显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9975037/

相关文章:

objective-c - 如何禁用 NSOutlineView 中元素的所有子树展开?

ios - 为什么我在 Storyboard (Xcode) 中所做的更改没有反射(reflect)在我的应用程序上?

iOS - 动画背景问题

ios - 通过键盘应用程序或 iMessage 应用程序截取屏幕截图

javascript - 在 Objective-C 中处理 Javascript onclick 函数

ios - 插入 block 回调到 NSMutableDictionary

ios - UIScrollView 页面宽度不等于 self.view 宽度

xcode - 更新到 Xcode 6.0 后,创建 NSManagedObject 子类不生成属性

iphone - 如果我不为 iPhone 和 iPad 创建单独的 xib,我的通用应用程序会被拒绝吗?

iphone - iPhone 中 Matt Gallagher 的 AudioStreamer - 无法配置网络读取流