如何在iPhone中重新加载或刷新视图?

Rah*_*yas 2 iphone xcode objective-c

我有一个uitableviewcontroller这里是.h文件代码

@interface addToFavourites : UITableViewController {

}

@end
Run Code Online (Sandbox Code Playgroud)

这是.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
Run Code Online (Sandbox Code Playgroud)

在另一个类中,我使用此代码显示此视图

addToFavouritesobj = [[addToFavourites alloc] initWithStyle:UITableViewStylePlain];
        [self.navigationController pushViewController:addToFavouritesobj animated:YES]; 
Run Code Online (Sandbox Code Playgroud)

我如何调用此类的重载方法uitableviewcontroller

不需要声明tableview,因为此视图会自动生成表格

我很困惑如何重新加载表格?

Kor*_*nel 12

addToFavouritesobj.tableView将为您提供UITableView对象的访问权限.

[addToFavouritesobj.tableView reloadData]
Run Code Online (Sandbox Code Playgroud)

BTW:类名应以大写字母开头.你班上的一个更好的名字就是AddToFavouritesController.