2011-09-18 73 views
2

我有UiViewController內的UITableView。 在同一屏幕上,我也有兩個按鈕:Show All vs Show Top 5.如何重新加載UiViewController內的UItableView

現在基於選擇全部/前5位,我必須更新表格數據。

我不能使用[tableView reloadData],因爲我沒有使用UITableViewController。

這是我第一次在iphone應用上工作。所以,任何幫助表示讚賞。

(我用這個教程上手http://www.icodeblog.com/2009/05/24/custom-uitableviewcell-using-interface-builder/

感謝。

這裏是我的代碼片段:

.h文件中

@interface DataViewController : UIViewController { 
    NSString *showType; 
} 

@property (nonatomic, retain) NSString *showType; 

-(IBAction) showTop: (id) sender; 
-(IBAction) showAll: (id) sender; 

@end 

.m文件

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *cellID = @"customCell"; 
    DataCustomCell *cell = (DataCustomCell *) [tableView dequeueReusableCellWithIdentifier:cellID];  

    if([showType isEqualToString:@"all"]) 
    { 
     // use this data.. 
    } 
    else 
    { 
     // use some other data.. 
    }  

    // .... 
} 

-(IBAction) showNearby: (id) sender 
{ 
    [email protected]"top"; 

    // reload table some way 
} 

-(IBAction) showAll: (id) sender 
{ 
    [email protected]"all"; 

    //reload table some way 
} 

回答

11

創建一個UITableView IBOutlet中這樣

@property (nonatomic, retain) IBOutlet UITableView *myTableView; 

在你的UIViewController的接口文件中。然後讓它連接到Interface Builder中的UITableView。在實現文件中合成之後,你應該能夠訪問它像這樣

[self.myTableView reloadData];

而且,因爲你保留它,你將不得不在dealloc方法來釋放myTableView。

+0

謝謝它的工作..完美... – priyank