gpt4 book ai didi

ios - 清除 reloadData 上的 tableView 不起作用?

转载 作者:行者123 更新时间:2023-12-01 17:02:37 24 4
gpt4 key购买 nike

我正在为我们公司编写一个简单的内部经济应用程序,但我遇到了一些问题。我使用来自动态生成的对象的信息填充 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 编程的新手,我真的需要一些帮助。

最佳答案

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

关于ios - 清除 reloadData 上的 tableView 不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4463427/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com