UITableView无法到达新行

时间:2013-10-23 13:55:21

标签: ios objective-c uitableview

我四处搜寻但一无所获。 当我向tableview添加一个新行时。我无法向下滚动到最后一个,但它在tableview中。 可能有点困惑。如果我向下滚动,我可以看到新的行,但不能停留在那个位置。一旦我发布,我只能看到倒数第二行。

此外,当用户单击一行时会有一个动作,该行会变大。此时,我可以向下滚动到最后一个。

有人可以帮帮我吗?

新更新: 可能是问题是由于自定义单元格。如果我使用默认单元格,那不是问题。

更新1:

由于很多人都希望看到代码,我会发布一些代码。但我不认为这会有所帮助。 这是工作代码。没问题。

- (void)addItemToArray {
    num++;
    [items addObject:[NSString stringWithFormat:@"Item No. %d", num]];
    [self.tableView reloadData];
}

- (void)delItemToArray {
    num--;
    [items removeLastObject];
    [self.tableView reloadData];
}


#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the 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];
    }

    // Configure the cell...
    cell.textLabel.text = [items objectAtIndex:indexPath.row];

    return cell;
}

但是如果我将UITableViewCell更改为我的自定义单元格CustomCell。我无法达到新的目标。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    // Configure the cell...
    cell.titleLabel.text = [items objectAtIndex:indexPath.row];

    return cell;
}

4 个答案:

答案 0 :(得分:1)

检查故事板中是否启用“滚动已启用”和“启用用户交互”选项为“是”并检查部分的行数。也许你达到了行数的极限。

祝你好运!

答案 1 :(得分:0)

我遇到了同样的问题,我找到的唯一解决方案是重新加载表格视图。请提交一份RADAR,因为提交报告的开发人员数量会推动Apple解决问题的速度。

答案 2 :(得分:0)

不确定这是否有效,但在添加新行时将tableView的contentSize设置得更高。告诉我它是怎么回事。 :)

答案 3 :(得分:0)

检查返回的单元格的高度。可能是单元格高度不正确,因此tableview的整个内容大小不正确。