Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
-(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; preview.text = "hello"; } return self; }
预览它是一个简单的 UILabel;
因为您的 iboutlets(UI 组件)是在 viewdidload 方法中加载的,所以 您无法在 init 中访问它们
仅仅因为您从 nib 创建了视图控制器并不意味着它会立即加载它。
您需要将需要创建ui组件的任何代码放在viewDidLoadie中
viewDidLoad
- (void)viewDidLoad { preview.text = "hello"; }
如果您检查,preview将nil在您的 init 方法中,因此在其上设置文本将不起作用!
preview
nil