标签: uinavigationcontroller

如何使用选项卡和导航控制器实例化视图控制器以进行深度链接?

我正在为我的应用程序实现深度链接,但无法正确实例化我的应用程序。对于我的应用程序链接,它打开了博客文章的详细信息页面,所以我像这样实例化它:

var controller = PostDetailController()
Run Code Online (Sandbox Code Playgroud)

问题是底部没有导航标题或选项卡栏。如何从头开始正确启动我的应用程序然后加载我的应用程序PostDetailController?

下面是我的故事板的样子,我试图直接链接到我的“Post Detail Controller”,但后面有所有以前的控制器,我该怎么做? 在此输入图像描述

uitabbarcontroller uiviewcontroller uinavigationcontroller ios swift

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

导航控制器工具栏大小和位置 - iOS Swift

您好,我目前正在 Swift 3 中开发一个应用程序。我在嵌入导航控制器的表视图控制器中遇到问题。我当前正在显示 navigationController 工具栏。但是,在初始表视图控制器上,我将导航栏设置为隐藏。这会导致工具栏被调整大小和重新定位。

有谁知道我如何重新加载工具栏以遵循以下代码行:(这在视图中会出现)

self.navigationController?.toolbar.frame = CGRect(x: 0, y: UIScreen.main.bounds.height-80, width: self.view.frame.size.width, height: 80)
Run Code Online (Sandbox Code Playgroud)

我无法找到如何使用以下命令隐藏导航栏后调整工具栏的大小:(这在视图中确实出现)

self.navigationController?.setNavigationBarHidden(true, animated: true)
Run Code Online (Sandbox Code Playgroud)

toolbar uinavigationcontroller ios swift

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

如果导航堆栈中不存在,则推送视图控制器

我想检查导航堆栈中是否存在视图控制器。如果存在,我需要弹出它,否则我需要将其推送到导航堆栈。我已经尝试过以下代码。如果它不存在,控制权将转移到 else 块,但我无法导航到屏幕。请帮我

 for aViewController in viewControllers! {

    if aViewController is TabProfileViewController {

      self.navigationController?.popToViewController(aViewController, animated: true)

     }

    else {

        let lvc = self.storyboard?.instantiateViewController(withIdentifier: "LoginViewController") as? LoginViewController
        self.navigationController?.pushViewController(lvc!, animated: true)
      }
}
Run Code Online (Sandbox Code Playgroud)

uinavigationcontroller pushviewcontroller swift

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

如何删除 UIBarButtonItem 左侧的填充?

我想使用自定义视图 作为 UINavigationController 中留下的 UIBarButtonItem,是否可以删除此处的左侧填充?

我已经尝试过了:

let  btn = UIButton()
btn.frame = CGRect(x: -50, y: -50, width: 44, height: 50)
btn.setImage(UIImage(name:"img").withRenderingMode(.alwaysTemplate), for: .normal)
btn.addTarget(self, action: #selector(openSetting), for: .touchUpInside)

let leftButtonBar = UIBarButtonItem(customView: btn)

self.navigationItem.leftBarButtonItems = ( [leftButtonBar , otherBtn ])
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

如何删除剩余空间设置图标

更新。厌倦了这段代码:

let view = UIView(frame: CGRect(x: 0, y: 0, width: 50, height: 
view.backgroundColor = .gray
let  btn = UIButton()
btn.frame = CGRect(x: -15, y: 0, width: 44, height: 50)
btn.setImage(UIImage(name:"img").withRenderingMode(.alwaysTemplate), for: .normal)
btn.addTarget(self, action: #selector(DashboardTabBarController.openSetting), for: .touchUpInside) …
Run Code Online (Sandbox Code Playgroud)

uinavigationcontroller ios swift

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

添加一个向后滑动的动作 swift 4

我已将其中一个视图控制器的导航栏中的后退按钮更改为自定义按钮,并为该按钮提供了按下时要执行的操作:

self.navigationItem.hidesBackButton = true
let backButton = UIBarButtonItem(image: UIImage(named: "backArrow"), style: .plain, target: self, action: #selector(self.back))
self.navigationItem.leftBarButtonItem = backButton
Run Code Online (Sandbox Code Playgroud)

这工作得很好,我可以使用以下方法保持向后滑动以弹出视图控制器:

self.interactivePopGestureRecognizer?.isEnabled = true
self.interactivePopGestureRecognizer?.delegate = self
Run Code Online (Sandbox Code Playgroud)

在我的导航控制器文件中。不幸的是,当我向后滑动时,我无法(或者我还没有弄清楚)调用back()视图控制器中更改后退按钮的函数。如何以及在哪里检测到我正在滑动返回,以便我可以调用特定视图控制器中的后退功能?

back uinavigationcontroller ios swift

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

iOS:以编程方式创建的 UINavigationController 的导航栏未扩展到安全区域

我希望导航栏扩展到以编程方式创建的 UINavigationController 中的安全区域。我正在开发一个项目,他们以编程方式创建初始视图控制器并在 SceneDelegate 中设置其导航栏:

    func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { 
    guard let windowScene = (scene as? UIWindowScene) else { return }
    
    window = UIWindow(windowScene: windowScene)
    let initialViewController = initViewController()
    let navigationCotnroller = UINavigationController(rootViewController: initialViewController)
    navigationBarConfiguration(navigationCotnroller)
    
    window?.rootViewController = navigationCotnroller
    window?.makeKeyAndVisible()
    
}

private func initViewController () -> UIViewController {
    let view_controller_to_be_returned = DeviceSearchVC()
    view_controller_to_be_returned.title = "Devices"
    return view_controller_to_be_returned
}

private func navigationBarConfiguration (_ controller: UINavigationController) {
    controller.navigationBar.prefersLargeTitles = true
    controller.navigationBar.largeTitleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white]
    controller.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor: …
Run Code Online (Sandbox Code Playgroud)

uinavigationcontroller navigationbar ios swift safearealayoutguide

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

iOS:无法更改导航栏颜色

无法更改导航栏背景颜色。我尝试将颜色设置为 navigationController?.navigationBar.backgroundColor 和 navigationController?.navigationBar.barTintColor,例如以下示例中的 UIColor.red,但是白色 UIImage 出现在视图层次结构中导航栏颜色上方,如下所示图片: https: //imguh.com/image/CBXaj

还尝试使导航栏半透明和不透明,但没有效果。我可以更改按钮颜色并自定义其他元素,但不能更改栏的背景颜色。感谢任何帮助。

uinavigationbar uinavigationcontroller ios swift

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

从自定义UITableViewCell中调用模态窗口

我有一个UITableView,在其中我以下面的方式创建一个自定义UITableViewCell:

ItemCellController *cell = (ItemCellController *)[tableView dequeueReusableCellWithIdentifier:ContentListsCellIdentifier];
...
cell = [[[ItemCellController alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ContentListsCellIdentifier] autorelease];
Run Code Online (Sandbox Code Playgroud)

我这样做可以获得touchesBegan和touchesEnded事件(这样我就可以实现长时间的触摸).使用NSLog我可以看到使用以下代码从touchesBegan方法中正确调用longTouch:

timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(longTouch:) userInfo:nil repeats:YES];
Run Code Online (Sandbox Code Playgroud)

问题是我无法从longTouch方法中调用模态窗口.

我尝试了以下,但我得到一个NSInvalidArgumentException - [ItemCellController navigationController]:无法识别的选择器发送到实例错误.

AddItemController *addView = [[AddItemController alloc] initWithNibName:@"AddItemView" bundle:nil];  

UINavigationController *controller = [[UINavigationController alloc] initWithRootViewController:addView];
controller.navigationBar.barStyle = UIBarStyleBlack;
[[self navigationController] presentModalViewController:controller animated:YES];
[controller release];
Run Code Online (Sandbox Code Playgroud)

所以问题是,如何在自定义UITableViewCell中调用模态窗口.

谢谢

iphone model-view-controller uitableview uinavigationcontroller

2
推荐指数
1
解决办法
5696
查看次数

带有presentModalViewController的UINavigationController

我有一个菜单屏幕,实现UINavigationController并在屏幕上,使用presentModalViewController,我放置另一个屏幕,我想要另一个UINavigationController.我试图实现另一个导航控制器来处理新的屏幕,但我要么在屏幕下方的1/8处获得一个导航栏,它会崩溃或什么都没有.我也尝试[[UINavigationController alloc] initWithRootViewController:navigationConroller]过没有成功.我只是pushViewController试图将下一个nib放在堆栈上,但这不起作用.我究竟做错了什么?

iphone uinavigationcontroller presentmodalviewcontroller

2
推荐指数
1
解决办法
4916
查看次数

如何在iphone应用程序中添加pop视图控制器的通知?

我见过iPhone MP-movie player的示例应用程序 - 控制器.

他们在示例代码中添加了通知.

// Register to receive a notification that the movie is now in memory and ready to play
[[NSNotificationCenter defaultCenter] addObserver:self 
                 selector:@selector(moviePreloadDidFinish:) 
                 name:MPMoviePlayerContentPreloadDidFinishNotification 
                 object:nil];
Run Code Online (Sandbox Code Playgroud)

在上面的代码中,当MPMoviePlayerController完成加载时,它会调用moviePreloadDidFinish方法.

同样,我想在用户按下导航栏上的按钮(通过导航控制器返回上一个视图控制器)时触发一个方法.

我不知道如何为此添加通知.

iphone xcode nsnotifications uiviewcontroller uinavigationcontroller

2
推荐指数
1
解决办法
5815
查看次数