Эта проблема возникла у двух моих контроллеров. Когда я запустил приложение, tableView даже не отображается, не говоря уже о данных, которые должны отображаться в таблице. Я не могу опубликовать снимок экрана, потому что моя репутация недостаточно высока.tableView не отображается
Вот мой код.
#import "OngoingTournamentTableViewController.h"
#import "TournamentTableViewCell.h"
#import "AppDelegate.h"
#define kOngoingTournamentURL [NSURL URLWithString:@"https://www.kimonolabs.com/api/d4leq2cs?apikey=xgp4nU6xA9UcBWSe0MIHcBVbAWz5v4wR"]
@interface OngoingTournamentTableViewController()
@property (nonatomic, strong) NSArray *ongoingTournament;
@end
@implementation OngoingTournamentTableViewController
- (void)viewDidLoad {
[super viewDidLoad];
dispatch_async(kBgQueue, ^{
NSData *data = [NSData dataWithContentsOfURL:kOngoingTournamentURL];
[self performSelectorOnMainThread:@selector(fetchedTournamentData:)
withObject:data waitUntilDone:YES];
});
// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)fetchedTournamentData:(NSData *)tournamentResponseData {
NSError *error;
NSDictionary *json = [NSJSONSerialization
JSONObjectWithData:tournamentResponseData
options:kNilOptions
error:&error];
NSArray *myOngoingTournament = [[json objectForKey:@"results"] objectForKey:@"collection1"];
self.ongoingTournament = myOngoingTournament;
[self.tableView reloadData];
NSLog(@"%@", self.ongoingTournament);
}
#pragma mark - Table view data source
- (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 [self.ongoingTournament count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"tournamentCell" forIndexPath:indexPath];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"tournamentCell"];
}
NSDictionary *tournaments = [self.ongoingTournament objectAtIndex:indexPath.row];
NSString *title = [[tournaments objectForKey:@"Title"] objectForKey:@"text"];
NSString *venue = [tournaments objectForKey:@"Venue"];
cell.textLabel.text = title;
cell.detailTextLabel.text = venue;
return cell;
}
@end
Я назначил классы таблице tableView и прототипу. Какие-либо предложения?
И я ничего не получаю на консоли, но в браузере хорошо работает.
Спасибо заранее и снова извините за то, что являетесь такой бременем.
не должен быть контроллером представления подкласса 'UITableViewController'? – rakeshbs
Вызывается ли метод источника данных? –
@PhillipMills, как я это делаю –