創建一個對象類從NSObject的
@interface TableClass:NSObject的
@屬性(非原子,強)的NSString *絲毫不差;
和進口modelClass在你的ViewController
dispatch_async(dispatch_get_main_queue()^ {
NSURLSession*session=[NSURLSession sharedSession];
NSURLSessionDataTask *dataTask = [session dataTaskWithURL:[NSURL URLWithString:@"https://itunes.apple.com/search?term=music"
] completionHandler:^(NSData的*數據,NSURLResponse *響應,NSError *錯誤){
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
NSLog(@"%@", json);
NSArray*entryarr=[json objectForKey:@"results"];
for (NSDictionary*appDict in entryarr) {
TableClass*tc=[[TableClass alloc]init];
//setting tittler
NSString*str=[appDict objectForKey:@"artistName"];
[tc setTittle:str];
NSLog(@"artist Name=%@",tc.tittle);
[_tableArray addObject:tc];
}
[self.tableView reloadData];
}]; [dataTask resume];
});
}
TableClass * tableclassModel = [[TableClass alloc] init]; tableclassModel = [_ tableArray objectAtIndex:indexPath.row];
cell.textLabel.text=tableclassModel.tittle;