我有很多.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