Mar*_*ton 2 iphone xcode objective-c 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];
}
Run Code Online (Sandbox Code Playgroud)
cellForRowatIndexPath可能您已经在::中完成了这行代码
cell.selectionStyle = UITableViewCellSelectionStyleNone;
Run Code Online (Sandbox Code Playgroud)
如果是,则将其替换为以下之一:
cell.selectionStyle = UITableViewCellSelectionStyleGray;
Run Code Online (Sandbox Code Playgroud)
或者
cell.selectionStyle = UITableViewCellSelectionStyleBlue;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11361 次 |
| 最近记录: |