我正在手动加载 nib 文件(为了 UIView 可重用性),用于加载 nib 文件的代码
- (NSArray*)loadMyNibFile
{
UINib *nib = [UINib nibWithNibName:@"customView" bundle:nil];
NSArray *topLevelObjs = [nib instantiateWithOwner:self options:nil];
NSLog(@"objects: %@", topLevelObjs);
return topLevelObjs;
}
加载笔尖名称后,我将其添加到 UIScrollView
NSArray *array = [self loadMyNibFile];
CustomView *view = [array objectAtIndex:0];
CGRect frame = CGRectMake(0, 0, 320, 216);
frame.origin.x = self.scrollView.frame.size.width * 2;
frame.origin.y = 99;
[view setFrame:frame];
[self.scrollView addSubview:view];
不是问题是,当我以这种方式加载 nib 文件时,init
并initWithNibName
没有调用方法,如何解决?
先感谢您,