概括
我正在重新利用 Apple 的Page Control项目。在 loadScrollViewWithPage: 中,我添加到滚动视图的视图控制器在屏幕上显示时没有初始化值,就好像直接从笔尖显示一样。
细节
这是我单步执行时似乎正在运行的代码:
CBFullScreenViewController *controller = [viewControllers objectAtIndex:page];
if ((NSNull *)controller == [NSNull null]) {
controller = [[CBFullScreenViewController alloc] init];
// Populate the view from the corresponding CBImage object
CBImage *imageObject = [imageArray objectAtIndex:page];
BOOL bookmarked = [imageObject.bookmarked boolValue];
controller.bookmarkButton.highlighted = bookmarked;
NSString *subtitle = imageObject.subtitle;
controller.closedSubtitleLabel.text = subtitle;
// <-- snip...more initialization --> //
controller.delegate = self;
[viewControllers replaceObjectAtIndex:page withObject:controller];
[controller release];
}
// 将控制器的视图添加到滚动视图 if (nil == controller.view.superview) { CGRect frame = scrollView.frame; frame.origin.x = frame.size.width * 页;frame.origin.y = 0; 控制器.view.frame = 框架;[scrollView addSubview:controller.view];//<< 控制器和子视图 } // 都有非空的,看似 // 此时的有效值
下面是 CBFullScreenViewController 中的 init 方法:
- (id)init {
if ((self = [super initWithNibName:@"CBFullScreenViewController" bundle:nil])) {
self.cover = [[UIImageView alloc] init];
self.homeButton = [[UIButton alloc] init];
self.tabView = [[UIButton alloc] init];
self.closedSubtitleLabel = [[UILabel alloc] init];
self.openSubtitleLabel = [[UILabel alloc] init];
// <-- snip...more initialization --> //
}
return self;
}
虽然过去 2 小时对此进行故障排除帮助我找到了一些不相关的内存泄漏,但我终其一生都无法弄清楚我所考虑的价值观发生了什么变化!
哦,值得一提的是,我的每个网点都有@synthesize,它们都与 IB 挂钩。截图在这里。