2012-09-20 72 views
0

我嘗試了大約一小時的時間,使得能夠在UITableView中重新編譯單元格。如何在UITableView中重新排序單元格

我創建細胞

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

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

// Set up the cell... 



cell.textLabel.text = [array objectAtIndex:indexPath.row]; 
cell.showsReorderControl = YES; 
return cell; 
} 

和我有這樣的:

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

和按鈕方法

- (IBAction)delete:(id)sender { 
if (self.btnLeft.tag == 0) { 
    self.btnLeft.title = @"Zakończ"; 
    [self.tableView setEditing:YES animated:YES]; 
    self.btnLeft.tag = 1; 
} 
else if (self.btnLeft.tag == 1) { 
    self.btnLeft.title = @"Edytuj"; 
    [self.tableView setEditing:NO animated:YES]; 
    self.btnLeft.tag = 0; 
} 
} 

但是當我點擊編輯按鈕i setEditing to YES,但我可以只刪除行,不重新排序。 當我有錯誤?我的意思是,右側單元格一側沒有重新排序圖標。

回答

1

好吧,我解決了它。

要使重排序控件出現,您不僅必須設置此屬性,還必須實現UITableViewDataSource方法tableView:moveRowAtIndexPath:toIndexPath :.另外,如果數據源實現tableView:canMoveRowAtIndexPath:返回NO,則重排序控件不會出現在該指定行中。

+0

我會殺了自己 - 我有這些方法,我設置了cell.showsReorderControl = YES;對於每個單元類...但沒有重排序控制器出現:/ – raistlin

相關問題