如何将UITableviewcell或UITableview设置为Empty?

时间:2009-10-21 05:11:43

标签: iphone

我正在使用rss feed。第一次,表格视图没有行。如果我按下按钮,将会出现值。如果我再次按下,表格视图有先前的值。收到数据后它会消失,新数据将会出现那时我按下按钮,就没有先前的价值了。我想要 删除它。我怎么能这样做?有什么帮助吗?

2 个答案:

答案 0 :(得分:0)

当您需要更新UITableView调用[tableView reloadData]方法的内容时。因此,如果到那时你已经清除了数据源中的先前数据,那么该表必须为空。

答案 1 :(得分:0)

UITableView由数据源工作。我将假设您已经按照Apple的方式设置了一个看起来像这样的表格:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
{   
    static NSString *identifier = @"identifier";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];

    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier] autorelease];
    }

    cell.textLabel.text = [_tableViewData objectAtIndex:[indexPath row]];

    return cell;
}

在此示例中,UITableView的数据存储在tableViewData数组中。其初始化如下:

_tableViewData = [[NSArray arrayWithObjects:@"cell 1", @"cell 2", @"cell 3", @"cell 4", nil] retain];

因此,当您想要将tableview的值更新为新的时,您需要更改tableViewData数组的值并在表视图上调用reloadData。

_tableViewData = [[NSArray arrayWithObjects:@"new cell 1" , @"new cell 2", @"new cell 3", @"new cell 4", nil] retain];
[_tableView reloadData];