【发布时间】:2010-09-07 15:55:17
【问题描述】:
我目前正在开发的 iOS 应用是基于标签栏的,其中一个标签是 UITableViewController。
问题是,当我使用空数据源(无论出于何种原因)打开此选项卡时,我想带来另一个带有某种消息/图像的视图,而不是使用 tableviewcontroller 获得的空白视图。
我尝试过类似的方法:
- (void)viewWillAppear:(BOOL)animated {
if ([myData count] == 0) {
if (!emptyView) {
emptyView = [[UIView alloc] initWithFrame:self.view.frame];
UILabel *emptyMsg = [[UILabel alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height / 2, self.view.frame.size.width, 20)];
emptyMsg.text = @"This is Empty !";
emptyMsg.textAlignment = UITextAlignmentCenter;
[emptyView addSubview:emptyMsg];
}
[self.view insertSubview:emptyView atIndex:0];
}
else {
if (emptyView != nil) { [emptyView removeFromSuperview]; emptyView = nil; }
[self.tableView reloadData];
[super viewWillAppear:animated];
}
}
在视图控制器中将 emptyView 定义为 iVar。
但它没有按预期工作,我找不到原因:/
你们中的任何人都可以看看并给我做这种行为的正确方法吗?
谢谢,
【问题讨论】:
-
myDatas...'data' 是复数...只是说
-
已修复!现在每个人都知道我不是以英语为母语的人 :p 谢谢 ;)
标签: iphone objective-c ios uitableview