2012-09-20 159 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

相关问题