поток JSON в таблицу - PullRequest
       3

поток JSON в таблицу

0 голосов
/ 04 марта 2012

У меня другая проблема на этот раз, я выбираю коды json, которые будут использоваться для заполнения таблицы, которая у меня есть в моей xib, так что, чтобы начать с моего .h файла

@interface FirstViewController : UIViewController<UITableViewDelegate, UITableViewDataSource, ASIHTTPRequestDelegate> {
NSMutableArray *resultArray;
IBOutlet UITableView *thetableView;
NSMutableData *responseData;

}

@property (nonatomic,retain) NSArray *arrayTypes;
@property (nonatomic,retain) NSMutableArray *resultArray;
@property (nonatomic,retain) IBOutlet UITableView *thetableView;

в моем файле .m я реализовал это

- (void) viewDidLoad{
responseData = [[NSMutableData data]retain];
NSURL *url = [NSURL URLWithString:@"http://localhost/fetch.php"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[[NSURLConnection alloc] initWithRequest:request delegate:self];    
[super viewDidLoad];
[self.thetableView reloadData];
}

в подключении: diffinishloading:

- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
[connection release];

NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
[responseData release];
NSLog(@"%@", responseString);
NSDictionary *dictionary = [responseString JSONValue];
NSMutableArray *response = [dictionary valueForKey:@"itemn"];
 resultArray = [[NSArray alloc] initWithArray:response];

}

и теперь проблема,В tableview реализованы методы numberofrowsinsection и didselectrowatindextpath, но последний никогда не вызывается, так как размер массива равен 0 и даже повторной загрузке, это не работает, я что-то пропустил или есть аналогичное руководство, которому нужно следовать?извините за длину, просто надеясь, что информация будет полезна

1 Ответ

0 голосов
/ 04 марта 2012

вы должны перезагрузить просмотр таблицы, как только у вас будут полные данные .. см. Обновленный код

- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
[connection release];

NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
[responseData release];
NSLog(@"%@", responseString);
NSDictionary *dictionary = [responseString JSONValue];
NSMutableArray *response = [dictionary valueForKey:@"itemn"];
 resultArray = [[NSArray alloc] initWithArray:response];

//Reload your table with data..
[self.thetableView reloadData];
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...