嗨有人能帮我理解如何在iOS 6.0中编辑时自动布局表格单元的组件?我已将AutoLayout FALSE设置为在属性检查器中右上角的UITableViewCell自动调整选项!单元格的右侧图像视图与删除按钮重叠。请参照附图。以下是此代码。无论如何,我可以解决这个问题吗?iOS 6:UITableView编辑和自动修复
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
PlayerCell *cell = (PlayerCell *)[tableView dequeueReusableCellWithIdentifier:@"PlayerCell"];
Player *player = [self.players objectAtIndex:indexPath.row];
cell.nameLabel.text = player.name;
cell.gameLabel.text = player.game;
cell.ratingImageView.image = [self imageForRating:player.rating];
return cell;
}
- (UIImage *)imageForRating:(int)rating
{
switch (rating)
{
case 1: return [UIImage imageNamed:@"1StarSmall.png"];
case 2: return [UIImage imageNamed:@"2StarsSmall.png"];
case 3: return [UIImage imageNamed:@"3StarsSmall.png"];
case 4: return [UIImage imageNamed:@"4StarsSmall.png"];
case 5: return [UIImage imageNamed:@"5StarsSmall.png"];
}
return nil;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
[self.players removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
}
我已经添加了下面的委托方法,当我滑动单元格时它工作正常。
-(void)tableView:(UITableView *)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath
{
PlayerCell *cell = (PlayerCell *)[tableView cellForRowAtIndexPath:indexPath];
cell.ratingImageView.hidden = YES;
}
- (void)tableView:(UITableView *)tableView didEndEditingRowAtIndexPath:(NSIndexPath *)indexPath
{
PlayerCell *cell = (PlayerCell *)[tableView cellForRowAtIndexPath:indexPath];
cell.ratingImageView.hidden = NO;
}
...但是当按下editButtonItem按钮时,这个方法不会被调用!真奇怪!我错过了一些东西。我添加了以下方法,当按下Edit/Done按钮时被调用,但没有办法检测将被选中编辑的单元格!
- (void)setEditing:(BOOL)editing animated:(BOOL)animate
{
[super setEditing:editing animated:animate];
if(editing)
{
NSLog(@"editMode on");
}
else
{
NSLog(@"Done leave editmode");
}
}
当用户点击左转按钮时,是否有添加选择器在该按钮上单击并获取单元格索引?
我没有设置右上UITableViewController不Imageview!我所有的方法都浪费!不能相信这是这么简单。非常感谢你!但只是想知道是否有任何方法,当我点击左键按钮编辑单元格时被调用?这是我无法想象的唯一的事情。 – applefreak
如果我不记得有错,你的单元格会通过UITableViewCellStateShowingDeleteConfirmationMask状态发送' - (void)willTransitionToState:(UITableViewCellStateMask)状态'。同样的方法被称为默认状态和编辑状态。 (看文档) –
我的意思是我已经设置了正确的UITableViewCell哪个did not; t工作! – applefreak