[英]numberOfRowsInSection not being called for UITableView
我在不重新加载UITableView时遇到一些问题,我已重做插座的链接以确保这不是问题。 我也尝试过使用[self table] reloadData],但这似乎也不起作用。 我已经调试了问题,但是它只是跳过了reloadData,并且应用程序一直在运行,就像没有代码一样。
我的.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;
}
}
我的.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;
谢谢你的帮助!
添加以下行:
- (void)viewDidLoad {
[super viewDidLoad];
self.table.dataSource = self;
self.table.delegate = self;
}
但是要容易得多,那就是在XIB文件的interface-build中设置数据源。
尝试这个
@interface SettingsCourses : UIViewController <UITableViewDelegate,UITableViewDataSource>
您似乎没有在设置表委托或数据源。 为此,只需在单位方法中添加以下代码
table.dataSource = self or wherever your data source is;
table.delegate = self:
您可能想尝试在接口构建器中断开并重新连接数据源和委托。 IB有时会“忘记”连接。
我已经在IB中设置了UITableViewController,但其类名与我拥有的UITableViewController文件不匹配。 新秀!
对我来说,错误是我在func numberOfSections(in tableView: UITableView) -> Int
返回0
func numberOfSections(in tableView: UITableView) -> Int
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.