在查看现有答案时,我认为 Steve's question and codelark's answer来解决我的问题。但我在这里遗漏了一些东西。
模态视图的 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中设置了标题:
导航项 - 新表单 -> 标题。
该标题是显示在 View 上的标题。使用在此论坛中找到的信息,我添加了以下几行:
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]];
仍然没有快乐。
我在这里遗漏了一些东西。有什么想法吗?
最佳答案
由于您没有将此 View Controller 推送到 UINavigationController 上,因此设置 newForm.navigationItem.title 不会成功。
看起来您正在插入一个包含其自己的导航栏的模态视图 Controller 。在这种情况下,您可能需要创建自己的引用并将 xib 中的栏绑定(bind)到它。
在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中的数据根本用不到。
关于ios - 在模态视图中设置导航项标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6373360/