2011-05-13 72 views
1

我想,當用戶掃描到一個UITableViewCell的權利做一些東西,所以我用問題與刷一個UITableViewCell

- (void)tableView:(UITableView *)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath 

但是我試圖向右滑動,這並沒有得到被調用,這是爲什麼?我所有的UITableView委託都被調用。

我也有這個在我的代碼:

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    return YES; 
} 


// Override to support editing the table view. 
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

} 

所有我想要做的是,當刷卡發生

+0

這很奇怪,因爲我只是試過同樣的事情,當我刷卡時它會調用它。我確定你有,但是你說你已經建立了你的tableView委託和dataSource到self,並且把tableView委託和dataSource協議放在頭文件中?沒關係的是,我相信麥克沃斯撞上了它的鼻子 – justin 2011-05-13 18:30:00

+0

它可能只是設置數據源而不是代表。 – 2011-05-13 19:19:13

+0

我已經設置了代理和數據源 – aherlambang 2011-05-13 20:23:52

回答

0

嘗試增加這個方法將你的tableView委託方法:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { 
     if (editingStyle == UITableViewCellEditingStyleDelete) { 
      // Delete the row from the data source. 
      [self.listTableView beginUpdates]; 
... 

我假設,因爲你的其他委託方法被調用,你包括在您的.h文件中@interface行?如果使用IB,你是否右鍵點擊tableview並連接委託和數據源?

0

設置表視圖的屬性添加一個子視圖

tableView.editing = YES; 
+0

我已經在viewDidLoad – aherlambang 2011-05-13 18:19:12

+0

裏面做過IBOutlet是否正確連接?做正確的以及左滑動...並檢查它是否正常工作... – 2011-05-13 18:21:25

1

你有tableView:commitEditingStyle:forRowAtIndexPath:方法嗎?

引述蘋果:

Note: A swipe motion across a cell does not cause the display of a Delete button 
unless the table view's data source implements the 
tableView:commitEditingStyle:forRowAtIndexPath: method. 

而且,刪除該方法在我的項目也使willBeginEditing不被調用。

+0

你把NSLog的canEdit和willBeginEdit?如果以編程方式進入編輯模式(setEditing:animated)會發生什麼?你是否實現了tableView:editingStyleForRowAtIndexPath:?如果是這樣,它說什麼,它是怎麼叫的? – mackworth 2011-05-13 19:14:17

1
// You missed this? 
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { 
    return YES; 
} 


- (UITableViewCellEditingStyle)tableView:(UITableView *)theTableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath { 
    return UITableViewCellEditingStyleDelete; 
} 


- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath { 
    return @"Remove"; 
} 


- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { 
    if (editingStyle == UITableViewCellEditingStyleDelete) { 
    [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES]; 
    } 
} 

希望有所幫助。

+0

我有這一切 – aherlambang 2011-05-13 18:37:12