numberOfRowsInSection not being called for UITableView
Asked Answered
E

6

10

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!

Equally answered 14/4, 2012 at 17:10 Comment(2)
Did you set the table view's dataSource?Henricks
Is the table connected with the delegate and the dataScource in the xib? Have you added the UITableViewDelegate, and UITableViewDataSource in the .h file?Brigadier
O
30

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.

Overfill answered 14/4, 2012 at 17:26 Comment(2)
Helped me too. Forgot to connect this! oopsRetire
This helped me no end.Kuibyshev
R
1

Try this

@interface SettingsCourses : UIViewController <UITableViewDelegate,UITableViewDataSource>
Retard answered 14/4, 2012 at 17:34 Comment(0)
S
0

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:
Sollie answered 14/4, 2012 at 17:24 Comment(0)
P
0

YOu might want to try to disconnect and reconnect datasource and delegate in the interface builder. IB sometimes "forgets" connections.

Pansypant answered 24/6, 2015 at 13:20 Comment(0)
I
0

I had setup a UITableViewController in IB, but its class name didn't match the UITableViewController file I had. Rookie!

Invade answered 21/11, 2015 at 21:14 Comment(0)
E
0

The error for me was that I was returning 0 in func numberOfSections(in tableView: UITableView) -> Int

Eolic answered 14/1, 2019 at 8:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.