我有很多.xib文件,我尝试以编程方式重新创建它们。navigationBar颜色和标题
唯一的问题是,我无法再自定义我的导航栏。
De版本函数被另一个视图与多个bar按钮项调用,所以代码对其他函数通用。
- (void)versions
{
VersionsViewController *verController = [[VersionsViewController alloc] initWithDocument:document];
[verController setDelegate:self];
[self loadPopupView:verController];
[verController release];
}
- (void)loadPopupView:(UIViewController *)viewController
{
if (popOverController != nil && [popOverController isPopoverVisible])
{
[popOverController dismissPopoverAnimated:YES];
}
if(![popOverController isPopoverVisible] || ![popOverController.contentViewController isKindOfClass:[viewController class]])
{
popOverController = [[UIPopoverController alloc] initWithContentViewController:viewController];
popOverController.popoverContentSize = CGSizeMake(320, 500);
UIBarButtonItem *buttonLocation;
if([viewController isKindOfClass:[CommentaryViewController class]])
buttonLocation = commentaryButton;
else if([viewController isKindOfClass:[PropertiesViewController class]])
buttonLocation = propertiesButton;
else
buttonLocation = versionsButton;
[popOverController presentPopoverFromBarButtonItem:buttonLocation permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
}
VersionsViewController.m
- (id)initWithDocument:(Document *)doc
{
self = [super init];
if(self)
{
self.document = doc;
self.title = @"other title"; //does not work either
//I just tried everything I could think of :P
self.navigationController.navigationBar.tintColor = [UIColor orangeColor];
self.navigationItem.titleView.backgroundColor = [UIColor redColor];
self.navigationController.navigationItem.titleView.backgroundColor = [UIColor greenColor];
self.navigationController.tabBarController.tabBar.backgroundColor = [UIColor blueColor];
self.navigationController.navigationBar.backgroundColor = [UIColor purpleColor];
}
return self;
}
有人可以看到我做错了什么?
编辑:
从self.title的NSLog和self.navigationController.title都是“空”
当我创建一个navigationController添加视图,并添加navigationController到弹出我得到2个酒吧和那么我可以设置navigationController的标题,但仍然不是颜色。
以编程方式创建它们的原因是性能。 .xib文件只是很大的XML文件,我只需要一个导航栏和一个表格视图,没什么复杂的。奇怪的是,我看到的标题女巫从未设置酒吧。当我创建一个navigationController添加视图,并将navigationController添加到弹出我得到2酒吧,然后我可以设置navigationController的标题,但仍然不是颜色。 – Justin
您不会通过删除nib文件来提高性能。 Nib文件被编译。 XIB文件是它们的XML源代码。有一个小的磁盘访问成本可以提高内存使用率。如果出现问题,可以通过访问视图控制器的view属性来预加载笔尖。解冻笔尖通常比生成物体便宜,因为所有的值都是冻干的。但是在这两种情况下的差别都很小,而不是性能优化的地方。 –
非常感谢您的好解释。我想我只是重新创建nib文件,如果没有它们,性能不是那么好。无论如何,这需要很多时间。再次感谢! – Justin