objective-c 如何在 iphone 中重新加载或刷新视图?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/959380/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to reload or refresh a view in iphone?
提问by Rahul Vyas
i have a uitableviewcontroller here is the .h file code
我有一个 uitableviewcontroller 这里是 .h 文件代码
@interface addToFavourites : UITableViewController {
}
@end
and here is the .m file code
这是 .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
and in another class i am showing this view using this code
在另一堂课中,我使用此代码显示此视图
addToFavouritesobj = [[addToFavourites alloc] initWithStyle:UITableViewStylePlain];
[self.navigationController pushViewController:addToFavouritesobj animated:YES];
how do i call reload method of this uitableviewcontrollerclass?
我如何调用这个uitableviewcontroller类的reload 方法?
there is no need of declaring tableview because this view automatically genrating a table
不需要声明 tableview 因为这个视图会自动生成一个表
i am very confused how to reload the table?
我很困惑如何重新加载表?
回答by Kornel
addToFavouritesobj.tableViewwill give you access to the UITableViewobject.
addToFavouritesobj.tableView将使您可以访问该UITableView对象。
[addToFavouritesobj.tableView reloadData]
BTW: class names should start with capital letter. A better name for your class would be AddToFavouritesController.
顺便说一句:类名应该以大写字母开头。为您的班级命名更好的名称是AddToFavouritesController.

