2012-04-14 10 views
4

私のUITableViewがリロードされていない問題がありますが、私は問題のないことを確認するためにコンセントのリンクをやり直しました。私は[self table] reloadData]を使っても試してみましたが、どちらもうまくいかないようです。私は問題をデバッグしましたが、単にreloadDataをスキップして、コードが実行されていなくてもアプリケーションは実行され続けます。numberOfRowsInSectionがUITableViewのために呼び出されていない

私の.mファイルの先頭部分には、何も私の.hファイル

の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; 
} 
} 
に任意の助け

#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

テーブルビューのデータソースを設定しましたか? – UIAdam

+0

テーブルは 'delegate'とxibの' dataScource'で接続されていますか? .hファイルに 'UITableViewDelegate'と' UITableViewDataSource'を追加しましたか? – Mat

答えて

25

は、この行を追加したときに、これはちょうど、次のコードを追加してください。

- (void)viewDidLoad { 
    [super viewDidLoad]; 

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

が、はるかに簡単にすることはXIBファイル別名インターフェース・ビルドでデータソースを設定することです。

+0

ありがとうございました! :) –

+0

あなたも私を助けました – RollRoll

+1

私も助けました。これを忘れてしまった!おっとっと – Tander

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ファイルと一致しませんでした。ルーキー!

関連する問題