Vid*_*dur 6 iphone objective-c interface-builder uiviewcontroller ios
我使用Interface Builder创建了一堆UI元素,并使用IBOutlets将它们连接到我的ViewController.
但是,当我尝试self.view.subviews在我的ViewController viewDidLoad方法中迭代时,我发现子视图数组为空.
ViewController.xib:
UIView
|
- UILabel
- UIButton
- // ... more stuff
- UIToolbar
Run Code Online (Sandbox Code Playgroud)ViewController.m:
#import "ViewController.h"
@interface ViewController ()
// Interface elements
@property IBOutlet UILabel *titleLabel;
@property IBOutlet UIButton *button1;
// ... etc
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// BREAK_POINT
// ... code to wire up the UIButtons to dynamically created objects
}
Run Code Online (Sandbox Code Playgroud)调试器输出位于BREAK_POINT:
(lldb) po self.view
<UIView: 0x7fa7897e2140; frame = (0 0; 600 600); autoresize = W+H; layer = <CALayer: 0x7fa7897e2210>>
(lldb) po self.view.subviews
<__NSArrayI 0x7fa789713500>(
)
(lldb) po [self.view.subviews count];
nil
(lldb) po self.button1
<UIButton: 0x7fa78955ea70; frame = (-23 -15; 46 30); opaque = NO; autoresize = RM+BM; layer = <CALayer: 0x7fa7897663d0>>
Run Code Online (Sandbox Code Playgroud)当UIButtons等已经初始化并正确连接到IBOutlets时,为什么self.views.subviews为空的任何想法?
编辑1:我将"MainView.xib"重命名为"ViewController.xib"并删除了loadView我的实现,我ViewController.m仍然看到相同的self.view.subviews行为.
尝试这样做
- (void)viewDidLayoutSubviews{
}
Run Code Online (Sandbox Code Playgroud)
加载所有子视图后调用此方法。希望对你有帮助 :)
| 归档时间: |
|
| 查看次数: |
1319 次 |
| 最近记录: |