标签: uinavigationcontroller

在Storyboard中切换UINavigationController堆栈的最佳实践

在我们的故事板中,我们有多个UINavigationController堆栈.例如,LoginViewController堆栈与堆栈完全分离SWRevealViewController.

切换它们的最佳做法是什么?当我按下注销按钮(注销按钮在SWRevealController堆栈上)然后尝试呈现LoginViewController堆栈时,我收到如下错误:

Warning: Attempt to present LoginViewController on SWRevealViewController whose view is not in the window hierarchy!
Run Code Online (Sandbox Code Playgroud)

即使我专门设置self.window.rootViewController为UINavigationControllerApp Delegate中的Login View Controller ,如下所示:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Spitfire" bundle:nil];
UINavigationController *nav = [storyboard instantiateViewControllerWithIdentifier:@"LoginNavigationController"];
LoginViewController *loginVC = [storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];

self.window.rootViewController = nav;
[nav presentViewController:loginVC animated:NO completion:nil];    
Run Code Online (Sandbox Code Playgroud)

有没有办法可以"解雇"当前的UINavigationController堆栈并使用新堆栈?或者也许我不应该在我的应用代理中调用此代码?

storyboard uinavigationcontroller ios

5
推荐指数
1
解决办法
3694
查看次数

QLPreviewController NavigationBar setTranslucent属性不起作用

我已经将自定义颜色设置为QLPreviewController的导航栏,但问题是我想在QLPreviewController中使用深色的导航栏,即使我已将导航栏半透明属性设置为否但我不知道为什么它不起作用

我希望它像下面的图像

在此输入图像描述

但它显示像这个图像

在此输入图像描述

QLPreviewController *previewer = [[QLPreviewController alloc] init];
// Set data source
[previewer setDataSource:self];
[previewer setDelegate:self];
// Which item to preview
[previewer setCurrentPreviewItemIndex:index];
[previewer.view addGestureRecognizer:singleTap];
previewer.navigationController.navigationBar.translucent = NO;
previewer.navigationController.navigationBar.barTintColor = [UIColor redColor];
self.navigationController.navigationBar.translucent=NO;
self.navigationController.navigationBar.barTintColor = [UIColor redColor];
   [self.navigationController pushViewController:previewer animated:TRUE ];
Run Code Online (Sandbox Code Playgroud)

即使我也尝试过这样但它也没有用

    - (id <QLPreviewItem>)previewController: (QLPreviewController *)controller previewItemAtIndex:(NSInteger)index
{
// Break the path into it's components (filename and extension)
// Use the filename (index 0) and the extension (index 1) to get path
//lblFileName.text=[strFileName stringByReplacingOccurrencesOfString:@"movefile" withString:@""];

// For navigation …
Run Code Online (Sandbox Code Playgroud)

iphone uinavigationbar uinavigationcontroller qlpreviewcontroller ios7

5
推荐指数
1
解决办法
4241
查看次数

仅为特定子视图控制器设置UINavigationBar的tintColor

我有一个基本的主 - 细节应用程序.根据在主列表中选择的项目,我只想tintColor在详细信息视图中设置导航栏.

我设置了这样的色调颜色:self.navigationController.navigationBar.tintColor = detailTintColor;在viewWillAppear:细节控制器中.

但是,这也会将主控制器导航栏的颜色更改为黄色(应保持红色),这在过渡动画期间可见为闪烁.我假设因为只有一个导航栏实例.

这里有一个截图来说明问题:

  • "i"图标位于主视图控制器的导航栏中,应为红色,而不是黄色

在此输入图像描述

uinavigationbar uinavigationcontroller tintcolor ios

5
推荐指数
1
解决办法
4245
查看次数

iOS 7 UIStatusBarStyle在应用程序启动错误期间隐藏状态栏

我正在更新我的应用程序以将导航栏的颜色从白色更改为蓝色.因此,我想将状态栏的颜色从黑色更改为白色.我已经尝试了Apple文档中的所有内容,这有助于我在Storyboard中更改所有View控制器的状态栏样式.

但是,我推到的任何笔尖都不在我的故事板中,使用presentViewController会自动更改UIStatusBarStyle - 这是我的推送代码:

NSString *url = @"https://twitter.com/Example";
                NSString *title = @"Example";
SocialWebViewController *addController = [[[SocialWebViewController alloc] initWithURL:url title:title] initWithNibName:@"SocialWebView_iPhone" bundle:nil];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:addController];
[self presentViewController:navigationController animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)

我已经在我的AppDelegate中放置了UIStatusBar首选样式,这对我的StoryBoard中的ViewControllers起作用,但是只有:

- (UIStatusBarStyle)preferredStatusBarStyle {
    return UIStatusBarStyleLightContent;
}
Run Code Online (Sandbox Code Playgroud)

是的,我已经尝试过了:

(1) [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];

(2) [self setNeedsStatusBarAppearanceUpdate];

(3)在plist中将UIViewControllerBasedStatusBarAppearance设置为YES

没有这个适用于那些不在我的StoryBoard中的笔尖.

确定所以我想出你所说的是什么 - 设置查看基于控制器的状态栏外观"否"不是为我工作因为我的状态栏在应用程序启动期间一直隐藏,因为我在设置时一直隐藏它UIViewControllerBasedStatusBarAppearance为"NO"...我该如何解决这个问题?

objective-c statusbar uinavigationcontroller ios

5
推荐指数
1
解决办法
5559
查看次数

如何以编程方式将UINavigationController添加到现有的UIViewController

我是iOS编程的新手,这个问题对某人来说可能看起来很愚蠢,对不起.我有一个问题是我有一个现有的UIViewController(A)和另一个UIViewController(B),我想在A上添加一个UINavigationController,当我按下A上的一个按钮时,我将导致B.我试过了以下方法,但它没有解决问题:

在AppDelegate中:

@synthesize navigationController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.

    self.tabbarController = [[UITabBarController alloc] init];
    UIViewController *viewController_1 = [[WUSTLViewController_1 alloc] init];
    UIViewController *viewController_2 = [[WUSTLViewController_2 alloc] init];

    UIViewController *viewController_3 = [[WUSTLViewController_3 alloc] init];
    navigationController = [[UINavigationController alloc] initWithRootViewController: viewController_3];

    self.tabbarController.viewControllers = [NSArray arrayWithObjects:viewController_1, viewController_2, navigationController, nil];
    self.window.rootViewController = self.tabbarController;

    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    return YES;
}
Run Code Online (Sandbox Code Playgroud)

在WUSTLViewController_3.h(A)中:

#import <UIKit/UIKit.h>
#import "WUSTLViewController_4.h"

@interface WUSTLViewController_3 …
Run Code Online (Sandbox Code Playgroud)

iphone objective-c uiviewcontroller uinavigationcontroller ios

5
推荐指数
1
解决办法
3万
查看次数

navigationController.viewControllers在iOS 8.2中的工作方式不同

在我的项目中,我使用一些代码来处理后退按钮,如下所示.

NSMutableArray *VCs = [NSMutableArray arrayWithArray: self.navigationController.viewControllers];
if ([[VCs objectAtIndex:[VCs count] - 2] isKindOfClass:[LoginViewController class]])
{
    [VCs removeObjectAtIndex:[VCs count] - 2];
    [VCs removeObjectAtIndex:[VCs count] - 2];
}
[self.navigationController setViewControllers: VCs];
Run Code Online (Sandbox Code Playgroud)

在iOS 7中,我得到了理想的结果.但是对于iOS版本8.2,可变数组VC中的值只是堆栈中的当前或topViewController.但后退按钮将导航到所有以前的viewcontrollers.但是导航堆栈中没有一个存在.在ios8中导航处理有什么变化吗?

我想从堆栈中删除登录屏幕viewcontroller,以便在单击后退按钮时,它不会返回到登录屏幕.我仅在iOS 8.2中遇到此问题(可能在iOS 8及更高版本中).可能是什么问题?

编辑:

在prepareForSegue:中,我使用以下代码:

if([[segue identifier] isEqualToString:@"mediaDetailSegue1"])
{
    MovieDetailViewController *movieDetail;
    if(isIOS8SystemVersion)
    {
        movieDetail = ([[segue destinationViewController]viewControllers][0]);
    }
    else
    {
        movieDetail = [segue destinationViewController];
    }

        movieDetail.videoData = [_mediaContentArray objectAtIndex:selectedIndex];
    }
Run Code Online (Sandbox Code Playgroud)

所以对于iOS版本大于8的代码

 movieDetail = ([[segue destinationViewController]viewControllers][0]);
Run Code Online (Sandbox Code Playgroud)

叫做.我认为这是导致这个问题的原因.我做错了吗?

objective-c uiviewcontroller uinavigationcontroller ios

5
推荐指数
1
解决办法
3414
查看次数

如何禁用导航控制器(Swift)中特定视图控制器的自动旋转?

^上面根本没有答案...存在问题,无法为导航控制器内部的特定(并非全部)视图控制器禁用自动旋转。类似的问题并不针对特定视图控制器禁用自动旋转的能力,而是针对导航控制器内部所有视图控制器禁用自动旋转的能力。我的导航控制器包含一些我想自动旋转的VC和其他我不想自动旋转的VC。没有现有的问题可以令人满意地回答。

xcode uiviewcontroller uinavigationcontroller swift

5
推荐指数
1
解决办法
2794
查看次数

如何在没有故事板Swift的情况下推出新视图

首先,我根本不想使用故事板.我能够"呈现"目标视图控制器,但我无法通过顶部的标准iOS后退按钮显示它.我的理解是我可以通过推动控制器而不是呈现它来实现这一点.我没有任何错误,但没有任何反应.

在按钮上单击此代码即可运行.注释代码成功呈现了ForgotPasswordPage:

//更改忘记密码页面

func forgotPasswordSwitch(sender: UIButton!) { 
   //let ForgotPassword:ForgotPasswordPage = ForgotPasswordPage()
   //self.presentViewController(ForgotPassword, animated: true, completion: nil)
    let ForgotPassword = ForgotPasswordPage()
    self.navigationController?.pushViewController(ForgotPassword, animated: true)
}
Run Code Online (Sandbox Code Playgroud)

uiviewcontroller uinavigationcontroller pushviewcontroller ios swift

5
推荐指数
1
解决办法
4421
查看次数

使用带MVVM Light的标签栏(iOS)

我有两个选项卡UITabBarController,两个都是UINavigationControllers.问题是初始化NavigationService需要一个UINavigationControlleras参数.我想要找到一种方法,以root身份使用导航控制器选项卡,或者找到一种方法将选项卡控制器作为root用户.

我最终有三个选择:

1. 

                /->  Ctrl 1 -> ctrl 2      
    Nav -> Tab - 
                \->  Ctrl 1 -> ctrl 2
Run Code Online (Sandbox Code Playgroud)

此选项有效,但使用另一个控制器时标签栏会丢失NavigateTo().这不是解决方案,我确实需要各处的标签.

2.
        /-> Nav -> Ctrl 1 -> ctrl 2      
   Tab - 
        \-> Nav -> Ctrl 1 -> ctrl 2
Run Code Online (Sandbox Code Playgroud)

这根本不起作用,因为SimpleIoc只需要a UINavigationController,并导致崩溃.显然,这根本不是解决方案.

3.

Navigate using segue or pushing controllers manually, the 'classic' way.
Run Code Online (Sandbox Code Playgroud)

这完全违背了使用MVVM-Light的目的,这也不是解决方案.

我在Stack Overflow上看到了另一篇文章,他最终选择了选项3.我希望在这里找到别的东西.

任何人都对这个可能的解决方案有任何想法吗?或者我是SOL?

mvvm uitabbarcontroller uinavigationcontroller ios

5
推荐指数
1
解决办法
403
查看次数

UINavigationController的setViewControllers在IOS10中添加后退按钮

注意到的奇怪的事情:当您使用setViewControllers:animated替换UINavigationController中的视图控制器堆栈时:动画过程中将显示后退按钮,动画完成后该按钮将消失。仅在iOS10(设备和模拟器)中找到,iOS8和9可以正常工作(无后退按钮)。有人遇到过这个问题吗?

back-button uinavigationcontroller ios10

5
推荐指数
1
解决办法
333
查看次数