【问题标题】:Clear the tableView on reloadData not working?清除 reloadData 上的 tableView 不起作用?
【发布时间】:2011-05-26 16:38:06
【问题描述】:

我正在为我们公司编写一个简单的内部经济应用程序,但我遇到了一些问题。我使用来自动态生成的对象的信息填充 UITableView,如下所示:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
    }
Payments *project = [appDelegate.projects objectAtIndex:indexPath.row];

if([project.parentProject isEqualToString:bottomTabBar.selectedItem.title]) {
    NSLog(@"%@ är lika med %@ index: %d",project.parentProject, bottomTabBar.selectedItem.title, indexPath.row);
    // Configure the cell...
    NSMutableString *changeInValue = [[NSMutableString alloc] initWithFormat:@"%d",[[project.amountsek objectAtIndex:0] intValue]-[[project.amountsek objectAtIndex:1] intValue]];
    if([changeInValue intValue] >= 0) {
        [changeInValue insertString:@"+" atIndex:0];
        cell.imageView.image = [UIImage imageNamed:@"up.png"];
    } else {
        cell.imageView.image = [UIImage imageNamed:@"down.png"];
    }

    NSMutableString *foreignCurrency = [[NSMutableString alloc] initWithString:@""];
    if(![project.currency isEqualToString:@"SEK"]) {
        [foreignCurrency appendFormat:@" - %@%d",project.currency,[[project.payments objectAtIndex:0] intValue]];
    }

    NSString *detailString = [[NSString alloc] initWithFormat:@"%@%d (%@)%@",@"SEK",[[project.amountsek objectAtIndex:0] intValue],changeInValue, foreignCurrency];

    [changeInValue release];
    [foreignCurrency release];

    cell.textLabel.text = project.name;
    cell.detailTextLabel.text = detailString;

    [detailString release];
}

project = nil;

return cell;}

一切都像魅力一样!然而!当我按下另一个 tabButton 时,我希望它重新加载表格并仅显示匹配的元素! (匹配工作正常,日志正确打印​​出所有内容)虽然,旧表格单元格在添加新单元格之前不会为空。

这是重新加载 tabItem 的代码:

- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
NSLog(@"Tab clicked: %d", item.tag);
[sourcesTable reloadData];
}

我该如何解决这个问题? 我是 iPhone 编程新手,我真的需要一些帮助。

【问题讨论】:

    标签: ios iphone uitableview reload


    【解决方案1】:

    请调用 [sourcesTable reloadData];在该 ViewController.m 的 viewWillAppear 方法中 每次出现您的视图时都会调用此调用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-01
      • 2022-06-14
      • 1970-01-01
      相关资源
      最近更新 更多