2011-06-11 89 views

回答

8

就爲您在TableView中委託方法的條件可以使selectionStyle:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    static NSString *categoryIdentifier = @"Category"; 
    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
    } 

    //Way to stop to choose the cell selection 
    if(indexpath.row == 0){ 
     cell.selectionStyle = UITableViewCellSelectionStyleNone; 
     // OR 
     cell.userInteractionEnabled=False; 
    } 
    //while rest of the cells will remain active, i.e Touchable 

    return cell; 

} 
+0

爲什麼indexpath.row == 0? – lilzz 2011-06-12 06:13:21

+0

這隻適用於您不需要單元格選擇的特定單元格。否則不需要這樣;) – 2011-06-12 07:47:01

+0

我同意「cell.userIneractionEnabled = False;」但改變選擇風格不*禁用用戶交互。 – helioz 2013-06-09 01:18:57

1

只需添加一個BOOL變量,您在動作開始時將其設置爲true。然後實現tableview委託的-[tableView:willSelectRowAtIndexPath:]方法,以便當該變量對於該索引路徑當前爲真時返回nil

1

或動作時,運行

cell.selectionStyle = UITableViewCellSelectionStyleNone; 
相關問題