簡體   English   中英

在模態視圖中設置導航項標題

[英]Setting Navigation Item Title in a modal view

在回顧現有的答案時,我認為Steve的問題和codelark的答案來自於我的問題。 但我在這里遺漏了一些東西。

我對模態視圖的xib:IFDNewFormViewController.xib:

View Controller
> Table View
>> View
>>> Navigation Bar
>>>> Navigation Item - New Form
>> View
>>> Toolbar
>>>> Bar Button Item - Cancel
>>>> Bar Button Item - Flexible Space
>>>> Bar Button Item - Done

按下按鈕時調用的方法:

IFDNewFormViewController.m:

- (void) newFormDisplay:(id)sender {
    // Show the Create Flightlog View
    IFDNewFormViewController *newForm = [[IFDNewFormViewController alloc] init];
    newForm.flightlogDelegate = self;
    newForm.dataType = [self ifdDataType];
    newForm.displayDataType = [NSString stringWithFormat:@"New %@",[self displayDataType]];
    newForm.title = [NSString stringWithFormat:@"Title %@",[self displayDataType]];
    newForm.navigationItem.title = [NSString stringWithFormat:@"NavItem.Title %@",[self displayDataType]];
    newForm.navigationController.title = [NSString stringWithFormat:@"NavController.Title %@",[self displayDataType]];
    newForm.modalViewController.title = [NSString stringWithFormat:@"ModalViewController.Title %@",[self displayDataType]];


    NSLog(@"iFDListViewController_Pad:newFormDisplay start form for dataType=%@ (%@)",[self ifdDataType], [self displayDataType]);
    [self presentModalViewController:newForm animated:YES];
    [newForm release];
}

我在xib中設置了標題:

導航項目 - 新表格 - >標題。

該標題是視圖上顯示的標題。 使用此論壇中的信息,我添加了以下行:

newForm.navigationItem.title = [NSString stringWithFormat:@"NavItem.Title %@",[self displayDataType]];
newForm.navigationController.title = [NSString stringWithFormat:@"NavController.Title %@",[self displayDataType]];
newForm.modalViewController.title = [NSString stringWithFormat:@"ModalViewController.Title %@",[self displayDataType]];

仍然沒有快樂。

我在這里遺漏了一些東西。 有任何想法嗎?

由於您沒有將此視圖控制器推送到UINavigationController,因此設置newForm.navigationItem.title將無法解決問題。

看起來你正在推動一個包含它自己的導航欄的模態視圖控制器。 在這種情況下,您可能需要創建自己的引用並將xib中的條綁定到它。

在IFDNewFormViewController.h中創建一個實例變量

    UINavigationBar *customNavBar;

和出口物業

    @property (nonatomic, retain) IBOutlet *UINavigationBar customNavBar;

在IFDNewFormViewController.m中:

    @synthesize customNavBar;

一定要在dealloc中釋放它,並在viewDidUnload中設置為nil。

編輯xib時,右鍵單擊導航欄,然后單擊並將“New Referencing Outlet”旁邊的空心圓拖動到文件所有者,然后選擇customNavBar。 這樣,屬性將在加載后包含xib中的欄。

在初始化IFDNewFormViewController時,請務必使用以下命令:

    IFDNewFormViewController *newForm = [[IFDNewFormViewController] alloc] initWithNibName:@"whatever-the-file-name-is" bundle:nil];

或者甚至不會使用xib中的數據。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM