Здравствуйте, я пытаюсь разобрать данные из json и получить значения, которые будут отображаться в ячейках.Настройка cell.textlabel.text из json array
Вот мой ViewController.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
{
IBOutlet UITableView *mainTableView;
NSMutableData *data;
}
@property (nonatomic, strong) NSArray *category;
@property (nonatomic, strong) NSArray *coursesArray;
@property (nonatomic, strong) NSDictionary *parsedData;
@end
Это то, что я имею в ViewController.m
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
parsedData = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
coursesArray = [parsedData valueForKey:@"courses"];
NSLog(@"coursesArray: %@", coursesArray);
category = [coursesArray valueForKey:@"category"];
NSLog(@"%@", category);
}
-(int)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
-(int)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 1;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MainCell"];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:@"MainCell"];
}
cell.textLabel.text = [NSString stringWithFormat:@"%@", [category objectAtIndex:indexPath.row]];
NSLog(@"%@", category);
return cell;
}
В connectionDidFinishLoading я вижу в журнал, правильные значения, но когда я пытаюсь проверить перед созданием ячейки я получаю null. Что я здесь делаю неправильно?
Спасибо! Это сделал трюк. – Pahnev