我有一个 NSMutableArray 包含序列号 1,2...,n 并有一个 UITableView 显示单元格垂直升序并按顺序显示。我将如何在视觉上和数据中以及在 NSMutableArray 中删除 1 和 n 之间的 m 行,然后将数据中已删除单元格之后的所有单元格的值减 1,并且在视觉上如此firstResponder 不会像 reloadData 方法调用那样放弃控制权?
@interface TableController : UIViewController
@property (nonatomic, retain) NSMutableArray *data;
@end
@implementation TableController
@synthesize data;
- (id)init
{
if(self = [super init]) {
data = [NSArray arrayWithObjects:@"1",@"2",@"3",@"4",@"5",nil];
}
return self;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [data count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [UITableViewCell new];
[cell.textLabel setText:[data objectAtRow:indexPath.row]];
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 20;
}
@end
我将如何删除第 3 行,然后将第 4 行和第 5 行分别变为 3 和 4?