gpt4 book ai didi

iphone - 如何让我的 UITableView Controller 填充?

转载 作者:行者123 更新时间:2023-11-28 19:22:17 25 4
gpt4 key购买 nike

jokesArray 是一个 NSArray

这是我来自 Web 服务的数据:

(
{
"_id" = {
"$id" = 4e91fd49c7e24cda74000000;
};
author = draper;
comments = (
{
author = adias;
comment = "amazing again";
}
);
created = {
sec = 1318118400;
usec = 0;
};
text = "This is a random post again";
title = "post # 2";
type = (
punjabi
);
},
{
"_id" = {
"$id" = 4e8cf1d6c7e24c063e000000;
};
author = faisal;
comments = (
{
author = adias;
comment = amazing;
},
{
author = nike;
comment = "I concur";
}
);
created = {
sec = 1317772800;
usec = 0;
};
text = "This is a random post";
title = "post # 1";
type = (
punjabi
);
}
)

请指出为什么我的 UITableView 没有被填充。

- (void)viewDidLoad
{
[super viewDidLoad];
jokesArray = [[NSArray alloc]init];
[self getJokes];
}


-(void) getJokes
{
NSURL *url = [NSURL URLWithString:@"http://someurl"];
__block ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setCompletionBlock:^{
// Use when fetching text data
NSString *responseString = [request responseString];

NSDictionary *resultsDictionary = [responseString objectFromJSONString];


jokesArray = [resultsDictionary allValues];

// Use when fetching binary data
// NSData *responseData = [request responseData];
}];
[request setFailedBlock:^{
NSError *error = [request error];
}];
[request startAsynchronous];
}


- (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 [jokesArray 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] autorelease];
}

// [[cell textLabel]setText:[jokesArray objectAtIndex:[indexPath row]]];

[[cell textLabel]setText:@"ok"];

return cell;
}

最佳答案

我认为您需要在分配 jokesArray 后为您的 UITableView 调用 reloadData 方法:

jokesArray = [resultsDictionary allValues];
[jokesArray retain]; // May be need if this is not retained property
[self.tableView reloadData];

关于iphone - 如何让我的 UITableView Controller 填充?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7706807/

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