2011-12-11 29 views
0

我正在使用下面的代碼來編輯一個可用視圖,但我只希望一個部分是可編輯的 - 我該怎麼做?我似乎無法訪問下面的編輯功能中的「部分」。只編輯一個可用視圖的一部分

在viewDidLoad中

self.navigationItem.rightBarButtonItem = self.editButtonItem; 

編輯功能:

- (void)setEditing:(BOOL)editing animated:(BOOL)animated { 

[super setEditing:editing animated:animated]; 
[tblSimpleTable setEditing:editing animated:YES]; 
if (editing) { 
    editButton.enabled = NO; 
} else { 
    editButton.enabled = YES; 
} 
    } 

謝謝。

回答

4

造成這種情況的邏輯是在你的表視圖控制器-tableView:canEditRowAtIndexPath:(數據源),像這樣:

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    // Replace 0 with whichever section you want editable 
    if (indexPath.section == 0) { 
     return YES; 
    } else { 
     return NO; 
    } 
} 

如果你繼承UITableViewController,你應該能夠評論存根方法中找到這在-tableView:cellForRowAtIndexPath:之下。

+0

作品似幻...謝謝! – TommyG

0
-(BOOL)tableView:(UITableView*)tableView canEditRowAtIndexPath:(NSIndexPath*)indexPath { 
     if (indexPath.section == <your target section disable>) { 
      return YES; 
     } 
     return NO; 
} 

你不需要寫的其他部分,canEditRowAtIndexPath返回默認NO

相關問題