添加子视图,但我什么也没看到 - iOS
我有一个控制器,其中有一些子视图。在代码中的某个时刻,我删除它们,然后添加它们。这是我用来添加它们的代码:
[self.view addSubview:dateLabel];
[self.view addSubview:tableView];
在这些行之后,我打印出:
NSLog(@"%@",[self.view subviews]);
我得到的输出是:
"<UINavigationBar: 0x614a8f0; frame = (0 0; 320 48); layer = <CALayer: 0x6129ee0>>",
"<UILabel: 0x614d500; frame = (0 48; 320 25); text = 'Dec. 15, 2010 - Jan. 15, ...'; clipsToBounds = YES; userInteractionEnabled = NO; layer = <CALayer: 0x614d570>>",
"<UITableView: 0x507ee00; frame = (0 73; 320 390); clipsToBounds = YES; layer = <CALayer: 0x9f57930>; contentOffset: {0, 0}>"
但是,我在屏幕上看到的唯一东西是导航栏。为什么标签和tableView不显示,即使这里说它是子View?
我还尝试在添加子视图后添加以下代码:
[self.view bringSubviewToFront:tableView];
[self.view bringSubviewToFront:dateLabel];
但它仍然不起作用。
I have a Controller of which I have a few subviews. At a certain point in the code, I remove them, and then later on, I add them. Here is the code I use to add them:
[self.view addSubview:dateLabel];
[self.view addSubview:tableView];
Right after these lines, I print out:
NSLog(@"%@",[self.view subviews]);
and the output I get is:
"<UINavigationBar: 0x614a8f0; frame = (0 0; 320 48); layer = <CALayer: 0x6129ee0>>",
"<UILabel: 0x614d500; frame = (0 48; 320 25); text = 'Dec. 15, 2010 - Jan. 15, ...'; clipsToBounds = YES; userInteractionEnabled = NO; layer = <CALayer: 0x614d570>>",
"<UITableView: 0x507ee00; frame = (0 73; 320 390); clipsToBounds = YES; layer = <CALayer: 0x9f57930>; contentOffset: {0, 0}>"
However, the only thing I see on my screen is the navigation bar. Why is the label and the tableView not showing up even if it says here that it is a subView?
I have also tried to add the following code after adding the subviews:
[self.view bringSubviewToFront:tableView];
[self.view bringSubviewToFront:dateLabel];
but it still does not work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的控制器是 UIViewController 吗?您检查过它是否已正确呈现吗?例如,使用presentModalViewController:self?
Is your controller a UIViewController? Have you checked it has been presented correctly? For example with presentModalViewController:self ?