app*_*eak 4 iphone uitableview autoresize ios ios6
嗨有人可以帮我理解如何在iOS 6.0中编辑时自动布局表格单元格的组件吗?我在"属性"检查器中将UITableViewCell Autosizing选项设置为右上角的AutoLayout FALSE!Cell的右侧图像视图通过删除按钮重叠.请参考附图.以下是此代码.无论如何我可以解决这个问题吗?
- (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];
}
}
Run Code Online (Sandbox Code Playgroud)
我添加了以下委托方法,当我滑动单元格时它工作正常.
-(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;
}
Run Code Online (Sandbox Code Playgroud)
...但是当我按下editButtonItem按钮时,不会调用此方法!真奇怪!我错过了什么.我添加了以下按下编辑/完成按钮时调用的方法,但无法检测将被选中进行编辑的单元格!
- (void)setEditing:(BOOL)editing animated:(BOOL)animate
{
[super setEditing:editing animated:animate];
if(editing)
{
NSLog(@"editMode on");
}
else
{
NSLog(@"Done leave editmode");
}
}
Run Code Online (Sandbox Code Playgroud)
当用户点击左侧圆形按钮时,无论如何都要在该按钮上添加选择器并获取单元格索引?

当您不使用AutoLayout时,您的ratingImageView使用自动调整大小调整大小并定位自己.默认情况下,这意味着左侧和顶部的距离是固定的,大小不会改变.
当您切换单元格以编辑已移动的contentView并调整大小但您的ratingImageView保持固定为顶部和左侧.您可以暂时(为了学习目的)将此背景颜色设置为单元格内容视图,并在编辑和删除单元格时查看它的大小调整.
你想要的是你的评级视图与右边缘而不是左边保持固定的距离.您可以通过设置ratingImageView的autoresizingMask属性在InterfaceBuilder(您执行XIB或Storyboard)或代码中更改此设置.
转到此选项卡

像这样更改自动调整大小

或者在代码中执行
// in code you specify what should be flexible instead of what should be fixed...
[ratingImageView setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5182 次 |
| 最近记录: |