2012-04-14 60 views
4

我有一些問題,我的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; 

感謝您的幫助!

+0

您是否設置了表視圖的dataSource? – UIAdam 2012-04-14 17:22:46

+0

該表是否與xib中的'delegate'和'dataScource'連接?您是否在.h文件中添加了'UITableViewDelegate'和'UITableViewDataSource'? – Mat 2012-04-14 17:24:50

回答

25

添加此行:

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    self.table.dataSource = self; 
    self.table.delegate = self; 
} 

,但很容易將設置在DataSource接口,建立又名XIB文件。

+0

謝謝你的工作! :) – 2012-04-14 17:44:30

+0

你也幫我解決了 – RollRoll 2012-08-22 01:53:47

+1

也幫助過我。忘記連接這個!哎呀 – Tander 2014-07-21 11:07:54

0

您似乎沒有設置表委託或數據源。要做到這一點只需添加以下代碼時,在你的單位方法

table.dataSource = self or wherever your data source is; 
table.delegate = self: 
1

試試這個

@interface SettingsCourses : UIViewController <UITableViewDelegate,UITableViewDataSource> 
0

你可能想嘗試斷開並重新連接數據源和委託在界面生成器。 IB有時會「忘記」連接。

0

我已經在IB中設置了UITableViewController,但是它的類名與我的UITableViewController文件不匹配。新秀!

相關問題