我觉得你说错了..我试着按你说的做,我创建了一个20个元素的表视图,添加了一个按钮,添加了20个元素,并称为“ reloadData”。结果是表格没有移动或滚动。新数据被添加到表格的末尾。我滚动到桌子的尽头后,我看到了它。
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.arr = [NSMutableArray new];
for (self.i=0; self.i<10; self.i++) {
[self.arr addObject:[NSString stringWithFormat:@"%d",self.i]];
}
[self.tableView setDelegate:self];
[self.tableView setDataSource:self];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.arr.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];
}
[cell.textLabel setText:self.arr[indexPath.row]];
return cell;
}
- (IBAction)addMoreDataToArr:(id)sender {
int oldI = self.i;
for (self.i = self.i; self.i<oldI+10; self.i++) {
[self.arr addObject:[NSString stringWithFormat:@"%d",self.i]];
}
[self.tableView reloadData];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
供参考:这是非常糟糕的代码:)它只是为了POC!
显示您的代码。 –
显示代码...... –
如果您发布了代码,以便可以检查您实际发生错误的位置 – z22