我有一些問題,我的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;
感謝您的幫助!
您是否設置了表視圖的dataSource? – UIAdam 2012-04-14 17:22:46
該表是否與xib中的'delegate'和'dataScource'連接?您是否在.h文件中添加了'UITableViewDelegate'和'UITableViewDataSource'? – Mat 2012-04-14 17:24:50