2011-06-16 57 views
3

在审查现有答案时,我认为Steve's question and codelark's answer是我最关心的问题。但我在这里错过了一些东西。在模态视图中设置导航项目标题

我对模式的看法厦门国际银行: 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]; 
} 

我在厦门国际银行设置标题:

导航项目 - 新窗体 - >标题。

该标题是在视图上显示的标题。使用在这个论坛中找到的信息,我添加了以下几行:

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]]; 

仍然没有快乐。

我很想念这里的东西。有任何想法吗?

回答

3

既然你没有把这个视图控制器放到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]; 

还是在厦门国际银行的数据甚至不会被使用。

+0

我已经添加了建议的代码。我需要在@property行中添加该类型。在分配了IFDNewFormViewController后,当我设置标题时,没有错误,但是xcode显示来自设置在.title =行结尾的断点“newFormNavBar(UINavigationBar *)0x0”。我在xib中验证了当在引用出口下单击View Controller - > Table View - > View - > Navigation Bar时:newFormNavBar < - 文件所有者。导航栏标题没有变化。仍读取xib中设置的“新窗体”。 – Kent 2011-06-16 17:27:29

+0

我确实得到了这个工作,对@tlbrack提供的解决方案进行了一些更改。更改:1.我引用了UINavigationItem,2.移动了一行代码:'newFormNavItem。title = [NSString stringWithFormat:@“Title%@”,[self displayDataType]];'viewWillAppear:(BOOL)animated' in IFDNewFormViewController.m。为什么不是在'IFDNewFormViewController * newForm = [[IFDNewFormViewController] alloc] initWithNibName:@“whatever-the-file-name-is”bundle:nil];后调用了newFormNavItem?我应该在最终更改中添加解决方案,还是将@ tlbrack标记为解决方案? – Kent 2011-06-17 01:39:15

相关问题