Reputation: 1058
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!
Upvotes: 10
Views: 15443
Reputation: 1714
The error for me was that I was returning 0
in
func numberOfSections(in tableView: UITableView) -> Int
Upvotes: 0
Reputation: 2681
I had setup a UITableViewController in IB, but its class name didn't match the UITableViewController file I had. Rookie!
Upvotes: 0
Reputation: 12884
YOu might want to try to disconnect and reconnect datasource and delegate in the interface builder. IB sometimes "forgets" connections.
Upvotes: 0
Reputation: 685
Try this
@interface SettingsCourses : UIViewController <UITableViewDelegate,UITableViewDataSource>
Upvotes: 1
Reputation: 10005
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.
Upvotes: 30
Reputation: 1098
You do not appear to be setting the table delegate or datasource. To do this just add the following code when in your unit method
table.dataSource = self or wherever your data source is;
table.delegate = self:
Upvotes: 0