简体   繁体   English

没有为UITableView调用numberOfRowsInSection

[英]numberOfRowsInSection not being called for UITableView

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. 我在不重新加载UITableView时遇到一些问题,我已重做插座的链接以确保这不是问题。 I have also tried using [self table] reloadData] but that does not seem to work either. 我也尝试过使用[self table] reloadData],但这似乎也不起作用。 I have debugged the issues, but it simply skips reloadData and the app keeps running like the code is not even there. 我已经调试了问题,但是它只是跳过了reloadData,并且应用程序一直在运行,就像没有代码一样。

Top part of my .m file, nothing is done in ViewDidLoad 我的.m文件的顶部,在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 我的.h文件

#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! 谢谢你的帮助!

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. 但是要容易得多,那就是在XIB文件的interface-build中设置数据源。

尝试这个

@interface SettingsCourses : UIViewController <UITableViewDelegate,UITableViewDataSource>

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:

YOu might want to try to disconnect and reconnect datasource and delegate in the interface builder. 您可能想尝试在接口构建器中断开并重新连接数据源和委托。 IB sometimes "forgets" connections. IB有时会“忘记”连接。

I had setup a UITableViewController in IB, but its class name didn't match the UITableViewController file I had. 我已经在IB中设置了UITableViewController,但其类名与我拥有的UITableViewController文件不匹配。 Rookie! 新秀!

对我来说,错误是我在func numberOfSections(in tableView: UITableView) -> Int返回0 func numberOfSections(in tableView: UITableView) -> Int

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM