Xcode UITableView Row 在选中时未突出显示
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9975037/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Xcode UITableView Row not highlighted when selected
提问by Mark Leighton
I have a working table view on my iphone app, and am implementing a second view using navigationController.
我在我的 iphone 应用程序上有一个工作表视图,并且正在使用导航控制器实现第二个视图。
But when I try to select a cell on the initial view, it does not respond i.e. no highlighting in blue, no selection.
但是当我尝试在初始视图中选择一个单元格时,它没有响应,即没有蓝色突出显示,没有选择。
Can anyone suggest what I might have missed, or what is responsible for actually selecting the cell when the user taps it?
任何人都可以建议我可能错过了什么,或者当用户点击它时实际选择单元格的原因是什么?
OK thanks for your suggestions - still no luck. here is my code:
好的,感谢您的建议 - 仍然没有运气。这是我的代码:
- (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];
}
回答by Neelam Verma
May be you have done this line of code in cellForRowatIndexPath
::
可能你已经在cellForRowatIndexPath
:: 中完成了这行代码
cell.selectionStyle = UITableViewCellSelectionStyleNone;
If yes, then replace it with either of these:
如果是,则将其替换为以下任一项:
cell.selectionStyle = UITableViewCellSelectionStyleGray;
or
或者
cell.selectionStyle = UITableViewCellSelectionStyleBlue;
回答by rohan-patel
Without looking at your code I would say you have to add this line in your cellForRowAtIndexPath
delegate method.
在不查看您的代码的情况下,我会说您必须在cellForRowAtIndexPath
委托方法中添加这一行。
[cell setSelectionStyle:UITableViewCellSelectionStyleBlue];
And also you have to implement this delegate method which gets called when you tap on cell of UITableView
..
而且你还必须实现这个委托方法,当你点击UITableView
..
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
}