我有一个带有几个UITableViews的应用程序,如果其中一个是空的,我想显示一些帮助文本,漂浮在UITableView前面:
“您似乎尚未为此列表创建任何内容。点按上方的按钮即可进行首次输入。”
如何在UITableView前面显示此视图?
这是一个快速的模型:
答案 0 :(得分:2)
在.h文件中声明
UIView * root;
<。>文件中的
导入QuartzCore / QuartzCore.h
- (void)viewDidLoad
{
[super viewDidLoad];
root = [[UIView alloc] initWithFrame:CGRectMake(60, 50, 220, 250)];
root.backgroundColor=[UIColor grayColor];
root.layer.cornerRadius=10;
UILabel *label=[[UILabel alloc] initWithFrame:CGRectMake(10, 100, 200, 50)];
label.backgroundColor=[UIColor clearColor];
label.numberOfLines=3;
label.font=[UIFont fontWithName:@"Arial" size:14];
label.lineBreakMode=UILineBreakModeTailTruncation;
label.textColor=[UIColor whiteColor];
label.text=@"Make your first entry by tapping the button at the top of the screen";
[root addSubview:label];
[self.view addSubview:root];
}
按钮内的事件方法
[root removeFromSuperview];
答案 1 :(得分:1)
在viewDidLoad / Appear中,
创建一个视图并将其添加为子视图[self.view addSubview:infoView]
。点击事件+按钮将其从超级视图[infoView removeFromSuperView]
答案 2 :(得分:0)
我会在numberOfRowsInSection中创建/删除视图(如果它是0然后显示视图)或者它被调用的任何内容。至于视图本身,在自定义视图中有一个UILabel。要添加圆角等,您可以访问视图的图层,这是一个CALayer。哦,并确保您有一个视图的ivar,以便您可以轻松地将其删除并检查它是否可见。并确保在显示视图时始终重新加载表视图,否则将不会调用numberOfRowsInSection。