我有一个场景,我的UINavigationController缺少后退按钮(左按钮),但点击左按钮似乎仍然有效.
我在这里发现了一个类似的问题:UINavigationController的后退按钮消失了吗? 通过不将标题设置为@""解决了这个问题,但这不是我的问题.是否有任何其他情况会导致此行为?
更新:
如果重要的是我的视图层次结构:我的MainWindow包含一个UINavigationView,它首先加载一个UIViewController(这个视图包含一个Map).当点击注释附件按钮时,它会加载UITableViewController.这个视图应该有后退按钮.
谢谢.
该程序有一个导航栏,通常当点击viewController1中的按钮时,它会转到viewController2.当单击viewController2中的按钮时,它将转到viewController3.并且用户可以使用导航栏中的后退按钮从viewController3导航回viewController2然后导航到viewController1.
我想创建一个按钮,以编程方式将用户从viewController1直接带到viewController3.然后用户可以从viewController3导航回viewController2到viewController1.
有没有办法将两个视图推入导航控制器?或者是实现理想行为的另一种方式?我该怎么设计呢?
我已经将UINavigationBar的高度定制为100px,我想在这个自定义栏上添加按钮.
一切都很好,除了按钮似乎想要坐在导航栏的底部,无论如何.我不能让它与导航栏的中心或顶部对齐.

这是代码; 首先,我在app delegate中创建一个导航控制器,并在右侧添加一个按钮.
// set main navigation controller
temp *tempc = [[temp alloc] initWithNibName:@"temp" bundle:nil];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:tempc];
UIBarButtonItem *navItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:nil action:nil];
[tempc.navigationItem setRightBarButtonItem:navItem];
[self.window addSubview:self.navigationController.view];
[self.window makeKeyAndVisible];
Run Code Online (Sandbox Code Playgroud)
然后我在"临时"视图控制器中调整导航栏的大小,如下所示:
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
CGRect frame = CGRectMake(0.0f, 0.0f, 320.0f, 100.0f);
[self.navigationController.navigationBar setFrame:frame];
[self.navigationController.navigationBar setAutoresizingMask:UIViewAutoresizingFlexibleBottomMargin];
}
Run Code Online (Sandbox Code Playgroud)
我还尝试向rightBarButtonItem添加自定义视图,但我无法将添加的自定义视图完全触及顶部.

这个不幸的尝试的代码:
// set main navigation controller
temp *tempc = [[temp alloc] initWithNibName:@"temp" bundle:nil];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:tempc];
UIView *customView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, …Run Code Online (Sandbox Code Playgroud) objective-c uinavigationbar uinavigationcontroller uinavigationitem ios
首先,一点背景.我是iOS开发的新手,我已经在.Net上呆了很长时间了,这也许就是为什么我甚至会问这个问题,但是这里也是如此.
基本设置是这样的.你有UINavigationController一个RootViewController,我们会打电话MasterViewController.当这个MasterViewController发生某些动作时,我们想钻进一个DetailsViewController.但是,我们还想将一些数据传递给DetailsViewController.
我的理解是,在以前的SDK版本中(iOS 5之前),这种方法与此类似:
@implementation MasterViewController
-(IBAction)someAction
{
DetailsViewController *dvc = [[DetailsViewController alloc]initWithNibName:@"DetailsView" bundle:nil];
dvc.someDataProp = [self getSomeDataSomeHow];
[[self navigationController] pushViewController:dvc animated:YES];
}
@end
Run Code Online (Sandbox Code Playgroud)
然而,现在,在iOS 5中,似乎现在使用Storyboard和segues完成.在XCode中,您将从MasterViewController设置为segue到DetailsViewController,然后在代码中执行以下操作:
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
[segue.destinationViewController setSomeDataProp:[self getSomeDataSomeHow]];
}
Run Code Online (Sandbox Code Playgroud)
我的问题基本上是这样的:老方法对我来说感觉更清洁了.您正在非常清楚地了解ViewController您正在推送到导航堆栈的类型,并且您可以轻松地在其上设置属性.然而,在新的方法中,destinationViewController是类型的id(出于显而易见的原因),它对我来说感觉不那么干净.再次,这可能是我的.Net方面出现,但这在iOS中常见吗?只是使用id并谨慎对待风?
我的UIBack按钮没有出现问题,我不确定是什么导致它.
这是我制作后退按钮图像的代码,它在我的第一个ViewController中:
UIImage *backButtonHomeImage = [[UIImage imageNamed:@"backButtonImage"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:backButtonHomeImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
Run Code Online (Sandbox Code Playgroud)
当您第一次进入下一个视图(由按钮中的segue完成)时,该按钮不可见,但可以看到要返回的文本.一旦我点击后退按钮,图像就会出现,并在下次单击时保持显示状态.
我不确定这是否与我的代码或它所在的文件或者它和iOS 7问题有关.
我想改变的标题字体颜色NavigationController在iOS使用Xamarin,但我无法改变它.
有人可以帮助我实现它吗?
请问我如何在导航栏下添加ProgressView?我尝试在这篇文章中使用解决方案:在导航栏下添加进度条,但是代码是用ObjectiveC语言编写的......我尝试翻译成Swift.这是我在NavigationController SubClass中添加的代码
import UIKit
class CustomNavigationController: UINavigationController {
@IBOutlet var Secondprogress: UIProgressView!
override func viewDidLoad() {
super.viewDidLoad()
NSLayoutConstraint.deactivateConstraints(self.view.constraints())
Secondprogress?.setTranslatesAutoresizingMaskIntoConstraints(false)
var navBar = self.navigationController?.navigationBar
Secondprogress.tag = 1
self.view.addSubview(Secondprogress)
var Constraint = NSLayoutConstraint(item: self.Secondprogress,
attribute:NSLayoutAttribute.Bottom,
relatedBy:NSLayoutRelation.Equal,
toItem:navBar,
attribute:NSLayoutAttribute.Bottom,
multiplier:1.0,
constant:-0.5);
self.view.addConstraint(Constraint);
Constraint = NSLayoutConstraint(item: self.Secondprogress,
attribute:NSLayoutAttribute.Left,
relatedBy:NSLayoutRelation.Equal,
toItem:navBar,
attribute:NSLayoutAttribute.Left,
multiplier:1.0,
constant:0);
self.view.addConstraint(Constraint);
Constraint = NSLayoutConstraint(item: self.Secondprogress,
attribute:NSLayoutAttribute.Right,
relatedBy:NSLayoutRelation.Equal,
toItem:navBar,
attribute:NSLayoutAttribute.Right,
multiplier:1.0,
constant:0);
self.view.addConstraint(Constraint);
Secondprogress.setTranslatesAutoresizingMaskIntoConstraints(false)
Secondprogress.hidden = false
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() …Run Code Online (Sandbox Code Playgroud) uinavigationbar uinavigationcontroller uiprogressview ios swift
当Apple Watch上按下后退按钮(箭头)时,我需要在第二个视图控制器上进行一些清理.当按下后退按钮/弹出视图时,是否有任何检测/处理方法?
注意 - 我不能使用'willDeactivate()'函数,因为它让我陷入循环中我想要做的事情.
back-button uinavigationcontroller popviewcontroller ios watchkit
我在我的第一个视图控制器上bool调用showSettings了一个可选变量,它被调用ViewController,我从SecondViewController后面弹出ViewController.
在我弹出之前,我想将bool设置为true.因为ViewController在内存中,实例化另一个视图控制器似乎是错误的.
最好的方法是什么?我不使用故事板,如果这对你的答案很重要.
谢谢你的帮助
从iOS 11开始,当我解雇时,我的应用程序中的状态栏是行为不端的.状态栏被取消时,状态栏的背景变为清晰状态.它在iOS 10中没有这样做.
我在一个非常简单的应用程序中重新创建了这个问题,我已经在Github上发布了:TestStatusBarBug.以下是所有相关代码:
AppDelegate.m
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[[UINavigationBar appearance] setBarTintColor:[UIColor grayColor]];
return YES;
}
@end
Run Code Online (Sandbox Code Playgroud)
ViewController.m
#import "ViewController.h"
@interface ViewController () {
BOOL _statusBarHidden;
}
@end
@implementation ViewController
-(BOOL)prefersStatusBarHidden
{
return _statusBarHidden;
}
-(UIStatusBarAnimation)preferredStatusBarUpdateAnimation
{
return UIStatusBarAnimationSlide;
}
- (IBAction)toggleStatusBar {
_statusBarHidden = !_statusBarHidden;
[UIView animateWithDuration:0.35 animations:^{
[self setNeedsStatusBarAppearanceUpdate];
}];
}
@end
Run Code Online (Sandbox Code Playgroud)
还有其他人遇到过这个问题吗?有修复或解决方法吗?
ios ×7
objective-c ×3
iphone ×2
swift ×2
back-button ×1
ios11 ×1
ios5 ×1
ios7 ×1
ios8 ×1
statusbar ×1
uistatusbar ×1
watchkit ×1
xamarin ×1
xamarin.ios ×1