Iphone 未调用UITableView的numberOfRowsInSection
我有一些问题,我的UITableView没有重新加载,我已经重新连接了插座,以确保这不是问题。我也尝试过使用[self table]reloadData],但这似乎也不起作用。我已经调试了这些问题,但它只是跳过了重新加载的数据,应用程序一直在运行,就像代码根本不存在一样 在我的.m文件的顶部,ViewDidLoad中没有任何操作Iphone 未调用UITableView的numberOfRowsInSection,iphone,objective-c,ios5,xcode4.2,Iphone,Objective C,Ios5,Xcode4.2,我有一些问题,我的UITableView没有重新加载,我已经重新连接了插座,以确保这不是问题。我也尝试过使用[self table]reloadData],但这似乎也不起作用。我已经调试了这些问题,但它只是跳过了重新加载的数据,应用程序一直在运行,就像代码根本不存在一样 在我的.m文件的顶部,ViewDidLoad中没有任何操作 #import "SettingsCourses.h" @implementation SettingsCourses @synthesize settingsCou
#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;
#导入
#导入“dataHandler.h”
@接口设置浏览器:UIViewController
@属性(强,非原子)DataHandler*DataHandler;
@属性(强,非原子)NSMutableArray*进程;
@属性(强、非原子)IBUIVIEW*设置冲刷;
@属性(非原子,强)id委托;
@属性(弱、非原子)IBUIButton*BackButton;
@属性(弱、非原子)IBUIButton*DeleteButton;
@属性(弱、非原子)IBUITableView*表;
-(iAction)删除:(id)发件人;
-(iAction)返回:(id)发送方;
谢谢你的帮助 您似乎没有设置表委托或数据源。要做到这一点,只需在unit方法中添加以下代码
table.dataSource = self or wherever your data source is;
table.delegate = self:
添加以下行:
- (void)viewDidLoad {
[super viewDidLoad];
self.table.dataSource = self;
self.table.delegate = self;
}
但在接口构建(又称XIB文件)中设置数据源要容易得多。试试这个
@interface SettingsCourses : UIViewController <UITableViewDelegate,UITableViewDataSource>
@接口设置浏览器:UIViewController
您可能希望尝试在interface builder中断开并重新连接数据源和委托。IB有时会“忘记”连接。我在IB中设置了一个UITableViewController,但它的类名与我的UITableViewController文件不匹配。菜鸟 我的错误是,我在中返回了0
func numberOfSections(在tableView:UITableView中)->Int
是否设置了表视图的数据源?表是否与xib中的委托和数据源连接?您是否已将UITableViewDelegate
和UITableViewDataSource
添加到.h文件中?对我也有帮助。忘了连接这个!哦,这帮了我很多忙。