Iphone 将数据放入UITableView时出现问题
我写这个代码Iphone 将数据放入UITableView时出现问题,iphone,objective-c,Iphone,Objective C,我写这个代码 - (void)requestFinished:(ASIHTTPRequest *)request { // Use when fetching text data NSString *responseString = [request responseString]; dataToDisplay = [[NSMutableArray alloc] init]; //NSString *myJSON = [[NSString alloc] init
- (void)requestFinished:(ASIHTTPRequest *)request
{
// Use when fetching text data
NSString *responseString = [request responseString];
dataToDisplay = [[NSMutableArray alloc] init];
//NSString *myJSON = [[NSString alloc] initWithString:responseString];
NSDictionary *json = [responseString JSONValue];
Status *statut = [[Status alloc] init];
statut.flyNumber = [json objectForKey:@"flynumber"];
statut.ftatuts = [json objectForKey:@"fstatuts"];
statut.escDepart = [json objectForKey:@"escdepart"];
statut.escArrival = [json objectForKey:@"escarrival"];
statut.proArrival = [json objectForKey:@"proarrival"];
statut.proDepart = [json objectForKey:@"prodepart"];
statut.estDepart = [json objectForKey:@"estdepart"];
statut.estArrival = [json objectForKey:@"estarrival"];
statut.realDepart = [json objectForKey:@"realdepart"];
statut.realArrival = [json objectForKey:@"realarrived"];
[dataToDisplay addObject:statut];
NSLog(@"ok");
}
- (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 [dataToDisplay 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];
}
// Configure the cell...
NSLog(@"1 ok");
Status *statut2 = [dataToDisplay objectAtIndex:indexPath.row];
NSLog(@"2 ok");
cell.textLabel.text = [NSString stringWithFormat:@"%@ - %@",statut2.flyNumber,statut2.ftatuts];
NSLog(@"3 ok");
return cell;
}
问题是桌子还是空的。控制台中没有“ok 1”消息。
这是我的控制器
#import <UIKit/UIKit.h>
#import "ASIHTTPRequest.h"
#import "JSON.h"
#import "Status.h"
@interface StatusTableViewController : UITableViewController {
NSString * Flynumber;
NSMutableArray *dataToDisplay;
}
@property(retain,nonatomic) IBOutlet NSString * Flynumber;
@end
#导入
#导入“ASIHTTPRequest.h”
#导入“JSON.h”
#导入“Status.h”
@接口状态TableViewController:UITableViewController{
NSString*Flynumber;
NSMutableArray*数据显示;
}
@属性(保留,非原子)IBNSSTRING*Flynumber;
@结束
我添加了[self.tableView reloadData]代码>和它的工作。
但是如何将每个结果放在一行(单元格)?您的控制器(?)是否符合UITableViewDelegate
和UITableViewDataSource
协议
@interface YourController : UIViewController <UITableViewDelegate, UITableViewDataSource> {...}
@interface YourController:UIViewController{…}
如果是,请检查以确保已设置dataSource
属性。通常,这被设置为self
如果您已经正确设置了所有其他内容,您是否会尝试在-(void)requestFinished:(ASIHTTPRequest*)request
的末尾执行重新加载数据
?要执行重新加载,您必须执行:
[self.tableView reloadData];
在requestFinished:function的末尾,是否设置了表视图的属性?否,但现在我尝试添加@property(nonatomic,assign)id数据源;然后在.m中合成它,但仍然不起作用也许你应该阅读一些文档:谢谢,但我一直不明白:/我甚至看了一段视频来了解如何做到这一点。。。我会在一个新问题中发布它对不起,但我不知道如何执行重新加载:(我不认为。我在post@Mehdi:如果有效,请不要忘记投票和/或接受答案,以通知问题已解决。