UITableViewController不刷新

时间:2011-12-08 12:52:40

标签: iphone cocoa-touch uikit uitableview

我有一个tabBar应用程序。在app委托中,我创建了一个NSMutableArray,一个UITableViewController和一个更新NSMutableArray的类(比如说B类)。 tabBar包含 a)tableViewController,它显示* booksArray中的数据 b)B类将数据添加到booksArray

tableView在首次加载时效果很好。问题是当阵列更新时,UItableViewContoller中没有触发任何更改(当我再次选择其选项卡时)。我必须使用代表团吗?我必须改变我的架构吗?

AppDelegate:

visibleBooks = [[NSMutableArray alloc] init];
UINavigationController *navController = [[UINavigationController alloc]
initWithRootViewController:booksTableViewController];

UITabBarController *tabBarController =  [[UITabBarController alloc] init];
NSArray *viewControllers = [NSArray arrayWithObjects:navController,qrViewController, nil];
[tabBarController setViewControllers:viewControllers];

在UITableViewController .h:

@class BookDetailedViewController;

@interface BooksTableViewController : UITableViewController {

    NSMutableArray *bookSource;
}

@property (nonatomic,retain) NSMutableArray *bookSource; // IS RETAIN OK?

- (id) initWithDataSource: (NSMutableArray *) source;

@end

在UITableViewController .m:

- (id) initWithDataSource: (NSMutableArray *) source
{
    [super initWithStyle:UITableViewStyleGrouped];
    [self setBookSource:source];
    [[self navigationItem] setTitle:@"Books"];

    return self;
}

1 个答案:

答案 0 :(得分:1)

每次更新数据源或显示[self.tableView reloadData]

时,您需要在UITableViewController中调用tableView.

这可以在您viewWillAppear:内的BooksTableViewControllertabBar:didSelectItem:内的UITabBarController内完成。

例如,将此代码段添加到BooksTableViewController

- (void) viewWillAppear:(BOOL) animated
{
    [super viewWillAppear:animated];
    [self.tableView reloadData];
} 
相关问题