2012-04-02 26 views
1

我的iPhone應用程序具有工作表視圖,並且正在使用navigationController實現第二個視圖。Xcode UITableView行選中時未突出顯示

但是,當我嘗試在初始視圖中選擇一個單元格時,它不響應,即沒有突出顯示藍色,沒有選擇。

任何人都可以提出我可能錯過了什麼,或者什麼是當用戶點擊它時真正選擇單元格的責任?

好的謝謝你的建議 - 仍然沒有運氣。這裏是我的代碼:

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

發佈您的代碼好友.. – 2012-04-02 10:51:35

+0

你有沒有實現的方法 - (空)的tableView:(UITableView的*)的tableView didSelectRowAtIndexPath方法:(NSIndexPath *)indexPath 告訴代表的現在選定了指定的行。 – 2012-04-02 10:52:06

回答

3

不看你的代碼我會說你必須在你的cellForRowAtIndexPath委託方法中加入這一行。

[cell setSelectionStyle:UITableViewCellSelectionStyleBlue]; 

,你也必須執行,當你對UITableView電池接頭都會調用此委託方法..

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


} 
3

可能是你已經做了這行代碼在cellForRowatIndexPath ::

cell.selectionStyle = UITableViewCellSelectionStyleNone; 

如果是的話,然後,用這些替代它:

cell.selectionStyle = UITableViewCellSelectionStyleGray; 

cell.selectionStyle = UITableViewCellSelectionStyleBlue; 
相關問題