如何重新加载UiViewController内的UItableView

问题描述:

我有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 
} 

创建一个UITableView IBOutlet中这样

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

在你的UIViewController的接口文件中。然后让它连接到Interface Builder中的UITableView。在实现文件中合成之后,你应该能够访问它像这样

[self.myTableView reloadData];

而且,因为你保留它,你将不得不在dealloc方法来释放myTableView。

+0

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