iPhone-Backbarbuttonim为零,触摸时不会突出显示
我有一个全屏modalView,名为:iPhone-Backbarbuttonim为零,触摸时不会突出显示,iphone,uinavigationcontroller,uibarbuttonitem,back-button,null,Iphone,Uinavigationcontroller,Uibarbuttonitem,Back Button,Null,我有一个全屏modalView,名为: PreferencesController *nextWindow = [[[PreferencesController alloc] initWithNibName:@"Preferences" bundle:nil] autorelease]; UINavigationController* navController = [[[UINavigationController alloc] initWithRootViewController:nextW
PreferencesController *nextWindow = [[[PreferencesController alloc] initWithNibName:@"Preferences" bundle:nil] autorelease];
UINavigationController* navController = [[[UINavigationController alloc] initWithRootViewController:nextWindow] autorelease];
[self presentModalViewController:navController animated:YES];
然后从这个角度,我提出了另一个观点:
MyController *nextWindow = [[[MyController alloc] initWithNibName:@"tmp" bundle:nil] autorelease];
[self.navigationController pushViewController:nextWindow animated:YES];
在这个新控制器中,我有一个viewDidLoad:
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"Borders";
self.navigationController.navigationBarHidden = NO;
}
这样做,BackbarButtonim不会激活,我的意思是触摸它不会突出显示它,也不会返回到以前的视图
事实上,self.navigationController.navigationItem.backBarButtonim为零。self.navigationController.navigationItem不是NIL
调用方的self.navigationController和内部调用视图具有相同的引用
问题是什么?当您将视图控制器推入导航控制器时,它的BackBarButtonim将设置为返回到上一个视图控制器,而不是LeftBarButtonim。如果设置leftBarButtonItem,则backBarButtonItem将隐藏,相同的位置将替换为leftBarButtonItem 你的代码根本没有设置leftBarButtonItem,所以它当然是零 编辑: 我的测试代码。我通过下面的代码检查了backButtonItem和leftBarButtonItem,它们是零。你是对的。但当我将后退按钮移到上一个视图时,它的颜色确实发生了变化,所以它被高亮显示。和以前的视图控制器相比,它工作得很好。所以我认为你的代码在其他地方是错误的,它使后退按钮处于非活动状态 清单1,RootViewController类
// RootViewController.h
#import <UIKit/UIKit.h>
@interface RootViewController : UIViewController {
}
@end
// RootViewController.m
#import "RootViewController.h"
#import "MyViewController.h"
@implementation RootViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"RootView";
MyViewController *childView = [[[MyViewController alloc] init] autorelease];
UINavigationController *navCtrl = [[[UINavigationController alloc] initWithRootViewController:childView] autorelease];
[self.navigationController presentModalViewController:navCtrl animated:YES];
}
@end
//RootViewController.h
#进口
@接口RootViewController:UIViewController{
}
@结束
//RootViewController.m
#导入“RootViewController.h”
#导入“MyViewController.h”
@RootViewController的实现
-(无效)viewDidLoad{
[超级视图下载];
self.title=@“RootView”;
MyViewController*childView=[[[MyViewController alloc]init]autorelease];
UINavigationController*navCtrl=[[UINavigationController alloc]initWithRootViewController:childView]autorelease];
[self.navigationController presentModalViewController:navCtrl动画:是];
}
@结束
清单2,MyViewController
// MyViewController.h
#import <UIKit/UIKit.h>
@interface MyViewController : UIViewController {
}
@end
// MyViewController.m
#import "MyViewController.h"
#import "MyAnotherViewController.h"
@implementation MyViewController
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"MyView";
NSLog(@"%s backBarButtonItem:%@ leftBarButtonItem:%@",__FUNCTION__ ,self.navigationItem.backBarButtonItem, self.navigationItem.leftBarButtonItem);
MyAnotherViewController *childView = [[[MyAnotherViewController alloc] init] autorelease];
[self.navigationController pushViewController:childView animated:YES];
}
@end
// MyAnotherViewController.h
#import <UIKit/UIKit.h>
@interface MyAnotherViewController : UIViewController {
}
@end
// MyAnotherViewController.m
#import "MyAnotherViewController.h"
@implementation MyAnotherViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"Another View";
}
@end
//MyViewController.h
#进口
@接口MyViewController:UIViewController{
}
@结束
//MyViewController.m
#导入“MyViewController.h”
#导入“MyAnotherViewController.h”
@MyViewController的实现
//实现viewDidLoad以在加载视图(通常从nib)后执行附加设置。
-(无效)viewDidLoad{
[超级视图下载];
self.title=@“MyView”;
NSLog(@“%s BackbarButtonim:%@LeftBarButtonim:%@”,“函数”,self.navigationItem.BackbarButtonim,self.navigationItem.LeftBarButtonim);
MyAnotherViewController*childView=[[MyAnotherViewController alloc]init]autorelease];
[self.navigationController pushViewController:childView动画:是];
}
@结束
清单3,MyAnotherViewController
// MyViewController.h
#import <UIKit/UIKit.h>
@interface MyViewController : UIViewController {
}
@end
// MyViewController.m
#import "MyViewController.h"
#import "MyAnotherViewController.h"
@implementation MyViewController
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"MyView";
NSLog(@"%s backBarButtonItem:%@ leftBarButtonItem:%@",__FUNCTION__ ,self.navigationItem.backBarButtonItem, self.navigationItem.leftBarButtonItem);
MyAnotherViewController *childView = [[[MyAnotherViewController alloc] init] autorelease];
[self.navigationController pushViewController:childView animated:YES];
}
@end
// MyAnotherViewController.h
#import <UIKit/UIKit.h>
@interface MyAnotherViewController : UIViewController {
}
@end
// MyAnotherViewController.m
#import "MyAnotherViewController.h"
@implementation MyAnotherViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"Another View";
}
@end
//MyAnotherViewController.h
#进口
@接口MyAnotherViewController:UIViewController{
}
@结束
//MyAnotherViewController.m
#导入“MyAnotherViewController.h”
@MyAnotherViewController的实现
-(无效)viewDidLoad{
[超级视图下载];
self.title=@“另一个视图”;
}
@结束
确保您的下一个UIViewController引用了UINavigationController
更新#1
我当前的应用程序是一个选项卡栏应用程序,因此当我需要设置导航控制器引用时,我只允许新的传入视图控制器从控制选项卡的基类引用导航控制器
很抱歉,前面的回答我完全错了,我希望这会对你有所帮助
更新#2
请在按下UIViewController之前尝试以下操作:
UIButton* backButton = [UIButton buttonWithType:101];
[backButton addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside]; [backButton setTitle:Title forState:UIControlStateNormal];
UIBarButtonItem *iButton = [[UIBarButtonItem alloc] initWithCustomView:backButton];
self.navigationController.navigationItem.leftBarButtonItem = iButton;
更新#3
将definePreferences方法复制并粘贴到项目中
-(IBAction) definePreferences:(id)sender {
PreferencesController *nextWindow = [[PreferencesController alloc] initWithNibName:@"Preferences" bundle:nil] ;
nextWindow.caller = self;
UINavigationController* navController = [[UINavigationController alloc] initWithRootViewController:nextWindow];
[self presentModalViewController:navController animated:YES];
}
更新#4
- 我在Prefrences 2 Nib文件中添加了导航栏
- 然后将其与Preferences 2 UIViewController中UINavigationItem类型的IBOutlet连接
- 在Prefrences2 UIViewController的ViewDidLoad:中,添加以下代码以确保添加了左栏项目[1]
- 然后是要处理返回的函数[2]
如果您需要我进一步解释,请告诉我。我有最终解决方案。
事实上,当从摄影机覆盖使用新控制器来显示新视图时,会出现问题。
导航栏有时不工作。
要使其正常工作,必须从ImagePicker本身调用第一个视图,而不是从self(覆盖)调用第一个视图。因此,您需要在覆盖上保留对选择器的引用:
self.picker = [[UIImagePickerController alloc] init];
[some initialisation of the picker]
// Insert the overlay
self.overlay = [[OverlayViewController alloc] initWithNibName:@"Overlay" bundle:nil];
-- HERE --self.overlay.pickerRef = self.picker;
self.picker.cameraOverlayView = self.overlay.view;
[self presentModalViewController:self.picker animated:NO];
- (IBAction) click:(id)sender {
PreferencesController *nextWindow = [[[PreferencesController alloc] initWithNibName:@"Preferences" bundle:nil] autorelease];
UINavigationController* navController = [[[UINavigationController alloc] initWithRootViewController:nextWindow] autorelease];
-- DO -- [self.pickerRef presentModalViewController:navController animated:YES];
-- DONT DO -- [self presentModalViewController:navController animated:YES];
}
然后在覆盖中:
self.picker = [[UIImagePickerController alloc] init];
[some initialisation of the picker]
// Insert the overlay
self.overlay = [[OverlayViewController alloc] initWithNibName:@"Overlay" bundle:nil];
-- HERE --self.overlay.pickerRef = self.picker;
self.picker.cameraOverlayView = self.overlay.view;
[self presentModalViewController:self.picker animated:NO];
- (IBAction) click:(id)sender {
PreferencesController *nextWindow = [[[PreferencesController alloc] initWithNibName:@"Preferences" bundle:nil] autorelease];
UINavigationController* navController = [[[UINavigationController alloc] initWithRootViewController:nextWindow] autorelease];
-- DO -- [self.pickerRef presentModalViewController:navController animated:YES];
-- DONT DO -- [self presentModalViewController:navController animated:YES];
}
那么就没有导航问题了……@Ahmad Kayyali:nextWindow.navigationController是一个只读属性。您能删除或修改您的答案吗?这样其他读者就不会尝试了。@@Ahmad Kayyali:请看我的编辑,我已经测试过两个NavigationController是否已设置且相同。所以问题似乎不在这里,我想让你测试一些东西,请,我想在navigationItem左侧按钮上显式插入一个新按钮,更新@艾哈迈德·卡亚利:我把我的项目的示例代码放在这里:你能看到哪里出了问题吗?你有两个选择:1。重新设计您的应用程序,使之成为基于导航的应用程序,或者像我刚才所说的2。修改您的项目以停止使用导航->推送控制器并使用“PresentmodalViewcontroller”,隐藏时使用“DismissModalViewController激活”这是您的决定。好的,我的错:-)但BackbarButtonim也是一样:它是零。我检查了它,发现您是对的。后座议员人数也为零。:-)但当我接触到这个问题时,背后的反对意见就突出了。我发现了一件有趣的事情,当根视图控制器的标题为nil时,将视图控制器推入导航控制器,导航栏上没有后退按钮。但是,在我为根视图控制器指定了一个标题并按下视图控制器后,我可以看到工具栏上的后退按钮。这是一种奇怪的行为。。。