Gen*_*ari 2 iphone objective-c uitableview ios
我在这里遇到了一个非常相似的问题:https://stackoverflow.com/questions/3160796/inserting-row-to-end-of-table-with-uitableviewrowanimationbottom-doesnt-animate,但没有给出答案.他的代码也和我的有点不同.
我有一个非常简单的例子,它是从导航应用程序模板构建的.
NSMutableArray *items;
- (void)viewDidLoad {
[super viewDidLoad];
items = [[NSMutableArray array] retain];
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addItem)] autorelease];
}
- (void)addItem{
[items insertObject:@"new" atIndex:0];
[self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:0 inSection:0]] withRowAnimation:UITableViewRowAnimationBottom];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return items.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLabel.text = [items objectAtIndex:indexPath.row];
return cell;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
[items removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationBottom];
}
}
Run Code Online (Sandbox Code Playgroud)
问题是,当我插入或删除表格中的最后一行时,动画根本不起作用; 该行只是出现或立即消失.这只发生在UITableViewRowAnimationBottom上,但这是以这种方式创建或删除表格单元格最有意义的动画.这是Apple框架中的错误吗?或者它是故意这样做的吗?将额外的单元格添加到计数中是否有意义,然后设置此单元格以使其看起来根本不存在,只是为了解决这种行为?
| 归档时间: |
|
| 查看次数: |
1870 次 |
| 最近记录: |