如何解决在模式视图中设置导航项标题
| 在审查现有答案时,我认为史蒂夫(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时,右键单击导航栏,然后单击“新引用出口”旁边的空心圆并将其拖动到文件所有者,然后选择customNavBar。这样,属性将在加载后包含来自您的xib的条。
初始化IFDNewFormViewController时,请确保使用以下内容:
IFDNewFormViewController *newForm = [[IFDNewFormViewController] alloc] initWithNibName:@\"whatever-the-file-name-is\" bundle:nil];
否则,甚至无法使用xib中的数据。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。