我这样做是这样的:
NSArray* nibViews = [[NSBundle mainBundle] loadNibNamed:@"MyCustomView" owner:nil options:nil];
self = [nibViews objectAtIndex: 0]; //here it would be best practice to loop through nibViews and get the first view that is member of your class.
此外,nib 文件中的视图设置为 aMyCustomView
而不是UIView
. 在这两行之后,您可以设置所需的任何值。但是请注意,如果您将框架设置为 super 例如,它将被 xib 文件中的值覆盖。所以最好在加载 nib 之后设置所有内容,而不是之前。
据我所知,UIView
加载viewDidLoad
时没有回调UIViewController
。
希望这可以帮助。
干杯!
编辑:
你可以这样做:
- (id)initWithInfo:(MyInfoClass *) selectedInfo Body:(NSString *) _body
{
if ((self = [super init]))
{
NSArray* nibViews = [[NSBundle mainBundle] loadNibNamed:@"MyCustomClass" owner:nil options:nil];
self = [nibViews objectAtIndex: 0];
[self setInfo:selectedInfo];
[self setBody:_body];
}
}
然后就用那个initWithInfo: Body:
方法。