pri*_*ank 2 objective-c uitableview uiviewcontroller xcode4
我在UiViewController中有一个UITableView.在同一个屏幕中,我还有两个按钮:Show All vs Show Top 5.
现在基于选择all/top 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
Run Code Online (Sandbox Code Playgroud)
.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
}
Run Code Online (Sandbox Code Playgroud)
ms8*_*s83 11
像这样创建一个UITableView IBOutlet
@property (nonatomic, retain) IBOutlet UITableView *myTableView;
Run Code Online (Sandbox Code Playgroud)
在你的UIViewController的接口文件中.然后将其连接到Interface Builder中的UITableView.在您的实现文件中合成它之后,您应该能够像这样访问它
[self.myTableView reloadData];
此外,由于您保留了它,因此您必须在dealloc
方法中释放myTableView .
归档时间: |
|
查看次数: |
3356 次 |
最近记录: |