numberOfRowsInSection没有被调用UITableView
问题描述:
我有一些问题,我的UITableView没有重新加载,我已经重做了连接的插座,以确保这不是问题。我也尝试过使用[self table] reloadData],但似乎也没有效果。我已经调试过这些问题,但它只是跳过reloadData,应用程序仍然像代码甚至不在那里运行。numberOfRowsInSection没有被调用UITableView
我.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;
感谢您的帮助!
答
您似乎没有设置表委托或数据源。要做到这一点只需添加以下代码时,在你的单位方法
table.dataSource = self or wherever your data source is;
table.delegate = self:
答
试试这个
@interface SettingsCourses : UIViewController <UITableViewDelegate,UITableViewDataSource>
答
你可能想尝试断开并重新连接数据源和委托在界面生成器。 IB有时会“忘记”连接。
答
我已经在IB中设置了UITableViewController,但是它的类名与我的UITableViewController文件不匹配。新秀!
您是否设置了表视图的dataSource? – UIAdam 2012-04-14 17:22:46
该表是否与xib中的'delegate'和'dataScource'连接?您是否在.h文件中添加了'UITableViewDelegate'和'UITableViewDataSource'? – Mat 2012-04-14 17:24:50