2009-06-06 17 views
2

私はここのUITableViewController を持っては.hファイルのコードiphoneでビューを再読み込みまたはリフレッシュするにはどうすればいいですか?

@interface addToFavourites : UITableViewController { 

} 

@end 

であり、ここで.mファイルコードに

#import "addToFavourites.h" 


@implementation addToFavourites 

- (id)initWithStyle:(UITableViewStyle)style { 
    if (self = [super initWithStyle:style]) { 
    } 
    return self; 
} 


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
    return 1; 
} 


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    return 5; 
} 


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString *MyIdentifier = @"MyIdentifier"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:MyIdentifier] autorelease]; 
    } 
    // Configure the cell 

    return cell; 
} 

@end 

で、別のクラスでは、私はこのコード

を使用して、このビューを示しています
addToFavouritesobj = [[addToFavourites alloc] initWithStyle:UITableViewStylePlain]; 
     [self.navigationController pushViewController:addToFavouritesobj animated:YES]; 

このuitableviewcontrollerクラスのリロードメソッドをどのように呼び出すのですか?

このビューが自動的に私はテーブルをリロードするかどうかは非常に混乱していますテーブル

をgenratingので、テーブルビューを宣言する必要はありませんか?

+3

あなたのコードについて軽度のご意見:Objective-Cでは、クラス名は大文字で始まります。あなたのaddToFavoritesクラスはAddToFavorites、AddToFavoritesControllerなどでなければなりません。私はAddFavoriteControllerを使用します。 Objective-Cの命名規則を使用すると、他の人があなたを助けやすくなります。たとえば、私は[addToFavorites alloc]を見て、allocがクラスメソッドであり、インスタンス上で呼び出すべきではないことを伝えようとしていました。 –

答えて

12

addToFavouritesobj.tableViewは、UITableViewオブジェクトへのアクセス権を与えます。

[addToFavouritesobj.tableView reloadData] 

ところで:クラス名は大文字で開始する必要があります。あなたのクラスのより良い名前はAddToFavouritesControllerです。

+0

reloadDataメソッドは他の場所で実装されていますか? – Picflight

+0

reloadDataはUITableViewのメソッドなので、どこからでもそのオブジェクトにアクセスできます。 – Kornel

関連する問題