numberOfRowsInSection not being called for UITableView
14,664
Solution 1
add this lines:
- (void)viewDidLoad {
[super viewDidLoad];
self.table.dataSource = self;
self.table.delegate = self;
}
but much easier would be to set the datasource in interface-build aka the XIB file.
Solution 2
Try this
@interface SettingsCourses : UIViewController <UITableViewDelegate,UITableViewDataSource>
Author by
Markus Tenghamn
Updated on June 23, 2022Comments
-
Markus Tenghamn almost 2 years
I am having some issues where my UITableView is not reloading, I have redone the linking of the outlet to make sure that was not the issue. I have also tried using [self table] reloadData] but that does not seem to work either. I have debugged the issues, but it simply skips reloadData and the app keeps running like the code is not even there.
Top part of my .m file, nothing is done in ViewDidLoad
#import "SettingsCourses.h" @implementation SettingsCourses @synthesize settingsCourses; @synthesize Delegate; @synthesize BackButton; @synthesize DeleteButton; @synthesize table; @synthesize courses; @synthesize dataHandler; - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization dataHandler = [[DataHandler alloc] init]; dataHandler.coursesDelegate = self; courses = [dataHandler fetchCourses]; NSLog(@"Debug Count: %i", [courses count]); } [table reloadData]; return self; } - (void) viewWillAppear:(BOOL)animated { [table reloadData]; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { if (courses) { NSLog(@"Count: %i", [courses count]); return [courses count]; } else { NSLog(@"Count: 0"); return 0; } }
My .h file
#import <UIKit/UIKit.h> #import "dataHandler.h" @interface SettingsCourses : UIViewController @property (strong, nonatomic) DataHandler *dataHandler; @property (strong, nonatomic) NSMutableArray *courses; @property (strong, nonatomic) IBOutlet UIView *settingsCourses; @property (nonatomic, strong) id Delegate; @property (weak, nonatomic) IBOutlet UIButton *BackButton; @property (weak, nonatomic) IBOutlet UIButton *DeleteButton; @property (weak, nonatomic) IBOutlet UITableView *table; - (IBAction)Delete:(id)sender; - (IBAction)Back:(id)sender;
Thanks for any help!
-
Robert J. Clegg almost 10 yearsHelped me too. Forgot to connect this! oops
-
Alec. almost 6 yearsThis helped me no end.