【发布时间】:2011-09-18 03:39:23
【问题描述】:
我在 UiViewController 中有一个 UITableView。 在同一个屏幕中,我还有两个按钮:Show All vs Show Top 5。
现在基于选择全部/前 5 个,我必须更新表数据。
我不能使用 [tableView reloadData],因为我没有使用 UITableViewController。
这是我第一次开发 iPhone 应用程序。所以任何帮助表示赞赏。
(我使用这个教程开始http://www.icodeblog.com/2009/05/24/custom-uitableviewcell-using-interface-builder/)
谢谢。
这是我的代码的 sn-p:
.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
{
self.showType=@"top";
// reload table some way
}
-(IBAction) showAll: (id) sender
{
self.showType=@"all";
//reload table some way
}
【问题讨论】:
标签: objective-c uitableview xcode4 uiviewcontroller