我有一个UIViewController需要使用UINavigationControllerDelegate,特别是willShowViewController方法.
我正在设置<UINavigationControllerDelegate>我的实现,然后我将委托设置为self in viewDidLoad(self.navigationController.delegate = self;).然后我实现了该willShowViewController方法并且它工作正常,但是当视图控制器从堆栈弹出时,存在内存泄漏并且我的应用程序崩溃.我已经尝试self.navigationController.delegate = nil;过这两种方式viewDidUnload,dealloc但它没有帮助.
我可以在我的一个viewcontrollers中实现此委托的正确方法是什么?
在我的应用程序中,我有以下配置来打开我的视图控制器:
当我写"pushViewController"时,我使用导航控制器,当我写"present"时,我使用了一个presentModalViewController.
firtsView -> (pushviewcontroller) -> secondOneView -> (present) -> thirdOneView -> (present) -> fourthView
firstView -> (pushviewcontroller) -> secondTwoView -> (present) -> thirdTwoView
Run Code Online (Sandbox Code Playgroud)
这是我的应用程序来组织我的视图控制器的方案.然后我的问题是:
什么是从返回的路上"fourthView"(也就是,当我去从后"fourthView"),以"secondTwoView"?
有办法吗?
xcode uiviewcontroller uinavigationcontroller presentmodalviewcontroller ios
在我的应用程序中我有视图,用户添加新对象,然后他点击"保存"按钮并转到主视图.但之后我们在主视图上看到"后退"按钮.我可以在没有"后退"按钮的情况下执行此segue(新对象 - >主窗口)吗?
我尝试了很多方法,但没有成功.
通过这种方式,我可以创建一个新的UIBarButtonItem并且它可以工作,问题是它像lockButton/ArrowBackButton一样锁定:
public override void ViewWillAppear (bool animated)
{
base.ViewWillAppear (animated);
this.NavigationItem.LeftBarButtonItem = new UIBarButtonItem ("Tillbaka", UIBarButtonItemStyle.Plain, delegate(object sender, EventArgs e) {
this.NavigationController.PopViewControllerAnimated (true);
});
}
Run Code Online (Sandbox Code Playgroud)
尝试了这个,但没有奏效:
public override void ViewWillAppear (bool animated)
{
base.ViewWillAppear (animated);
this.NavigationItem.SetHidesBackButton(false,true);
}
Run Code Online (Sandbox Code Playgroud) c# uinavigationcontroller uibarbuttonitem xamarin.ios uinavigationitem
我已经尝试了各种隐藏我的后退按钮的方法 UINavigationController
UINavigationController RVC = new UINavigationController();
other code
RVC.NavigationItem.SetHidesBackButton(true,true);
Run Code Online (Sandbox Code Playgroud)
和其他类似的方式,但他们都没有实际隐藏后退按钮.有谁知道我做错了什么?
以下是我的AppDelegate:
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
customViewController = [[CustomViewController alloc] initWithNibName:@"CustomViewController" bundle:nil];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:customViewController];
[self.navigationController setNavigationBarHidden:YES];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
Run Code Online (Sandbox Code Playgroud)
在实际的XIB中,视图与"文件所有者"相关联,这是我唯一的关联.
XIB层次结构:
Navigation Controller
- View Controller - Root View Controller
-View (Associated with File's Owner)
Run Code Online (Sandbox Code Playgroud)
对不起,如果我不明白这一点,它在以前推出的应用程序上工作正常,但我明白这并不意味着它是正确的.
编辑:对不起,这是我得到的错误:
*由于未捕获的异常'UIViewControllerHierarchyInconsistency'终止应用程序,原因:'视图一次最多只能与一个视图控制器关联!查看<UIView:0xa192d00; frame =(0 20; 320 460); autoresize = W + H; layer = <CALayer:0xa192d60 >>与<UIViewController:0xa195c70>相关联.在将此视图与<CustomViewController:0xa1802a0>关联之前清除此关联.
iphone objective-c uiviewcontroller uinavigationcontroller ios6
I want to make a back swipe like the one in iOS 7.I'm still new with the whole iOS development, this is what I'm currently using.
Currently I have a pan gesture that detects if the user swipes back and then it just pops the navigation controller.
UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)];
[self.view addGestureRecognizer:pan];
-(void)handlePan:(UIPanGestureRecognizer *)sender{
CGPoint tran = [recognizer translationInView:recognizer.view];
CGPoint vel = [recognizer velocityInView:recognizer.view];
if(vel.x > 500 && tran.x > 100){
[self.navigationController popViewControllerAnimated:YES];
}
}
Run Code Online (Sandbox Code Playgroud)
I …
uinavigationcontroller ios uiswipegesturerecognizer uipangesturerecognizer ios7
我搜索了一个答案,但找不到任何解决我问题的方法.
所以这就是问题所在:我有一个自定义的UINavigationController,在创建它时supportedInterfaceOrientations,在rootViewController上调用该方法(仅支持肖像).但是当将其他ViewController推送到堆栈时,不会在推送的ViewController上调用此方法(支持除了倒挂之外的所有方法).
我解决它通过调用[self supportedInterfaceOrientations]的viewDidLoad-方法,但我认为这不是解决问题的好办法.
我希望你能帮助我解决这个问题.
这是我在第二个viewController中实现的代码.
- (BOOL)shouldAutorotate {
return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
[[[UIApplication sharedApplication] delegate] setGlobalOrientationMask:UIInterfaceOrientationMaskAllButUpsideDown];
return UIInterfaceOrientationMaskAllButUpsideDown;
}
else {
[[[UIApplication sharedApplication] delegate] setGlobalOrientationMask:UIInterfaceOrientationMaskAll];
return UIInterfaceOrientationMaskAll;
}
}
Run Code Online (Sandbox Code Playgroud)
我认为来自johnMa的解决方案应该适用于大多数应用程序,但在我的情况下,我认为有一个特殊的问题,但我现在自己解决了(不确定它是否是一个好的,但它的工作原理).
我- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated在navigationController-delegate上实现了该方法.
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
if (DEF_SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7")) {
if ([viewController respondsToSelector:@selector(supportedInterfaceOrientations)]) {
[viewController supportedInterfaceOrientations];
}
}
}
Run Code Online (Sandbox Code Playgroud)
我希望这可以帮助其他人解决同样的问题.
我正在学习iOS开发并遇到导航控制器的一些问题.
我创建了一个SingleView应用程序,然后使用"嵌入导航控制器"来获得导航控件.
我遇到的问题是,在应用程序成功构建之后,只有导航栏可见,其他UI组件只是纯黑色.我试过真正的设备,清理/重建,删除应用程序和重新构建,都得到了相同的结果.
以下是截图:

故事板的屏幕截图:

单击导航控制器时:

我已经尝试更新约束和框架,因此没有琥珀色三角形警告.
已经勾选了"初始视图控制器".
码:
AppDelegate.m
#import "AppDelegate.h"
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application
{
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to …Run Code Online (Sandbox Code Playgroud) 我正在开发一个自定义相机应用程序,我以模态方式呈现3个viewControllers.在每个segue,我使用prepareForSegue函数传递数据.我的问题是在完成相机工作后,我需要再显示2个需要在navigationController中的viewControllers.
我已经意识到,如果我没有传递任何数据,导航控制器工作正常.但是,当我传递数据时,应用程序在运行时崩溃.这样做的正确方法是什么?
这是我对segue功能的准备;
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "camera2Crop"{
let controller: CropViewController = segue.destinationViewController as CropViewController
controller.photoTaken = self.photoTaken
}
}
Run Code Online (Sandbox Code Playgroud)
在哪里photoTaken是一个UIImage对象.此外,这里是我的故事板的截图,我在其中放置了navigationController.我将prepareForSegue函数调用CustomCameraViewController为segue CropViewController.

编辑:我已将prepareForSegue更改为以下代码;
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "camera2Crop" {
let controller: CustomNavigationController = segue.destinationViewController as CustomNavigationController
controller.photoTaken = self.photoTaken
}
}
Run Code Online (Sandbox Code Playgroud)
现在应用程序没有崩溃,但我不知道如何通过导航控制器发送对象
ios ×8
iphone ×3
objective-c ×3
xcode ×3
ios7 ×2
xamarin.ios ×2
c# ×1
cocoa-touch ×1
ios6 ×1
mono ×1
orientation ×1
segue ×1