gpt4 book ai didi

iphone - 将数据加载到 uiviewcontroller 中的 uitableview

转载 作者:行者123 更新时间:2023-11-28 17:35:45 26 4
gpt4 key购买 nike

我正在尝试从通过解析 json 生成的数组加载数据...我肯定在数组中有 json 数据,但甚至没有调用 TableView 方法...我有 TableView 嵌入到常规 uiviewcontroller 中,它会编译并且表中的所有内容都不会加载任何数据。

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [transactions count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"any cell"];

if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"any cell"] autorelease];
}

NSLog(@"got here");
cell.textLabel.text = [names objectAtIndex:indexPath.row];
cell.detailTextLabel.text = [prices objectAtIndex:indexPath.row];
return cell;
}

- (void)viewDidLoad
{
[super viewDidLoad];
names = [[NSMutableArray alloc] init];
prices = [[NSMutableArray alloc] init];
[self requestTransactionData];
}

这是我的 .h 文件...

@interface Controller1 : UIViewController
<UITableViewDelegate, UITableViewDataSource>
{
UIActivityIndicatorView *loadingIndicator;

IBOutlet UITableView *myTableView;
IBOutlet UILabel *totalLabel;

NSMutableArray *names;
NSArray *transactions;
NSMutableArray *prices;
}

@property(nonatomic, retain) IBOutlet UIActivityIndicatorView *loadingIndicator;
@property(nonatomic, retain) IBOutlet UILabel *totalLabel;

@property(nonatomic, retain) UITableView *myTableView;

我不能为这个项目使用 ARC。我还在界面生成器中正确连接了它……这些看起来很简单,但出于某种原因我无法弄清楚。有什么建议么?

谢谢

最佳答案

  1. 我不明白你是怎么知道数据源方法没有被调用的。您没有记录所有这些。如果在填充 transactions 之前调用 numberOfRowsInSection 或为 nil,则它返回零,到此结束。

  2. 尝试使用延迟性能调用 reloadData,以便在 transactions 填充后发生。 TableView 不会神奇地知道你的数据何时准备好;你必须告诉它。

关于iphone - 将数据加载到 uiviewcontroller 中的 uitableview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9855883/

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