我试图从模态视图控制器隐藏iPad键盘,但它不起作用.我已经尝试过resignFirstResponder,但如果我们在模态视图控制器中,这没有任何影响.我在非模态UINavigationController中尝试了resignFirstResponder,它具有完全相同的UIViewController并且键盘正确隐藏.
有谁知道如何解决这个问题?
谢谢.
[更新]看起来我的代码有问题,因为resignFirstResponder确实有效(我做了一个简单的测试用例而不是使用我的代码).但我仍然不知道问题是什么.
iphone objective-c uinavigationcontroller ipad modalviewcontroller
我有一个控制器/视图的通用项目列表,可以扩展显示自定义列表..列表和导航工作正常..但我无法更改UINavigationController的标题.在通用控制器中:
- (void)viewDidLoad
{
[super viewDidLoad];
[self.view addSubview: navigationController.view];
}
- (void)setNavigationTitle: (NSString *)title
{
NSLog(@"set title: %@", title); // this works
self.navigationController.title = title; // Nothing works here
}
Run Code Online (Sandbox Code Playgroud)
然后,扩展类做..
- (void)viewDidLoad
{
[super viewDidLoad];
[self setNavigationTitle: @"Custom list"];
}
Run Code Online (Sandbox Code Playgroud)
navigationBar仍然有"Item"作为标题:(
我一直在尝试更改我的应用程序的UINavigationBar的背景图像.我尝试了几种方法.首先,我在AppDelegate类中添加了以下代码:
@implementation UINavigationBar (CustomImage)
- (void)drawRect:(CGRect)rect {
UIImage *image = [UIImage imageNamed: @"navigationbar.png"];
[image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
}
@end
Run Code Online (Sandbox Code Playgroud)
但它没有用.我的下一个尝试是编写一个覆盖drawRect方法的CustomizedNavigationBar类.它看起来像那样:
CustomizedNavigationBar.h
#import <UIKit/UIKit.h>
@interface CustomizedNavigationBar : UINavigationBar
@end
Run Code Online (Sandbox Code Playgroud)
CustomizedNavigationBar.m
#import "CustomizedNavigationBar.h"
@implementation CustomizedNavigationBar
- (void) drawRect:(CGRect)rect {
UIImage *image = [UIImage imageNamed: @"navigationbar.png"];
[image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
NSLog(@"I got called!!!!!");
}
@end
Run Code Online (Sandbox Code Playgroud)
在我定义NavigationBar的.xib文件中,我将类更改为新的CustomizedNavigationBar.但它仍然无法正常工作..
作为另一个测试,我下载了一个示例项目,其中应该更改背景图像.但即使使用该示例代码也无法正常工作.
我究竟做错了什么?我正在使用IOS 5.我可以定义背景图像的任何建议或其他方式吗?
谢谢你的回答!
按照一些指南遇到问题,特别是 http://blog.originate.com/blog/2014/04/22/delinklinking-in-ios/
我正在设置网址方案,它可以很好地从另一个应用程序启动应用程序,但传入主机或网址似乎不应该正常工作.我正在为所有视图布局使用故事板和界面构建器.
该指南在appDelegate中显示了这个openURL:
-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation{
if([[url host] isEqualToString:@"page"]){
if([[url path] isEqualToString:@"/page1"]){
[self.mainController pushViewController:[[Page1ViewController alloc] init] animated:YES];
}
return YES;
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的版本简化,并从其他一些来源迅速,即 获取ViewController的实例从AppDelegate在Swift中我正在跳过url主机的条件,以删除问题中潜在的其他变量.
func application(application: UIApplication, openURL url: NSURL, sourceApplication: String, annotation: AnyObject?) -> Bool {
var rootViewController = self.window!.rootViewController
let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
var profileViewController = mainStoryboard.instantiateViewControllerWithIdentifier("profile") as ProfileViewController
rootViewController.navigationController.popToViewController(profileViewController, animated: true)
return true
}
Run Code Online (Sandbox Code Playgroud)
swift版本导致崩溃:
fatal error: unexpectedly found nil while unwrapping an Optional value
似乎rootViewController还没有navigationController呢?
uiviewcontroller uinavigationcontroller ios appdelegate swift
好的,所以情况如下:
我有一个应用程序,我只希望UINavigationController中的一个特定视图具有横向方向.这个视图是一个UIImageView,我正在捕获一个签名(这部分工作真棒).所以,像这样:
previous view --> signature view --> next view
(portrait) (landscape) (portrait)
Run Code Online (Sandbox Code Playgroud)
我似乎无法找到一种强制方法来强制设备方向在该签名屏幕上显示横向.在签名视图上具有纵向方向永远不会有意义,因为在该屏幕宽度上签名的空间确实不足.
那么,关于如何实现这一点的任何好主意?我考虑过可能以模态方式进行签名视图,从而打破导航控制器.思考?
我有一个带左右按钮的导航栏,我需要在右键旁边放另一个按钮.有谁知道我怎么能这样做?以下是一些有用的代码:
- (id)init {
self = [super initWithStyle:UITableViewStyleGrouped];
if (self) {
_pinArray = [[NSArray alloc]init];
_pinArray = [Data singleton].annotations;
UIBarButtonItem *right = [[UIBarButtonItem alloc]initWithTitle:@"Map"
style:UIBarButtonItemStylePlain
target:self
action:@selector(goToMap:)];
self.navigationItem.rightBarButtonItem = right;
UIBarButtonItem *left = [[UIBarButtonItem alloc]initWithTitle:@"Menu"
style:UIBarButtonItemStylePlain
target:self
action:@selector(goToMenu:)];
self.navigationItem.leftBarButtonItem = left;
self.navigationItem.title = @"My Homes";
}
return self;
}
Run Code Online (Sandbox Code Playgroud) 在我的应用程序中,我有一些自定义标题(字体不是字体)存储在png中,我想将其作为导航的标题.我希望标题中的字母对于每个不同的视图控制器都具有相同的大小,因此在插图画家中我努力使它具有相同的大小和宽度(提供空白以考虑更短的字符串).我做以下事情:
UIImageView *titleImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"SelectAnAlbumTitleLettering"]];
titleImageView.contentMode = UIViewContentModeCenter;
self.navigationItem.titleView = titleImageView;
[titleImageView release];
Run Code Online (Sandbox Code Playgroud)
并且看起来图像被任意调整大小并基于每个元素包括的元素navigationBar(即后退按钮,右按钮等)定位.
我想知道,我怎样才能获得控制权,titleView所以我可以让它实现我想要的大小和位置,因此不会随意调整大小/重新定位.
iphone cocoa-touch uinavigationbar uinavigationcontroller ios
使用iOS我现在有15个ViewControllers我想从一个ViewController弹出到另一个View Controller.
我正在使用此代码:
SecondViewController *Sec=[SecondViewController alloc]init];
[self.navigationController popViewController:Sec animated:YES];
Run Code Online (Sandbox Code Playgroud)
这显示错误this ViewController not exist,然后我使用此代码:
NSArray *array = [self.navigationController viewControllers];
[self.navigationController popToViewController:[array objectAtIndex:1] animated:YES];
Run Code Online (Sandbox Code Playgroud)
此代码适用于从thirdViewController弹出到secondViewController.但是当我们从第九个(第9个)ViewController弹出到第五个(第五个)ViewController然后我在第九个(第9个)ViewController中使用这个代码时发生了什么:
NSArray *array = [self.navigationController viewControllers];
[self.navigationController popToViewController:[array objectAtIndex:4] animated:YES];
Run Code Online (Sandbox Code Playgroud)
它不会从Ninth(第9个)ViewController弹出到第五个(第五个)ViewController,它将第九个(第9个)ViewController弹出到第八个(第8个)ViewController.我不知道当我们使用这条线时发生了什么:
NSArray *array = [self.navigationController viewControllers];
NsLog(@"array = %@",array);
Run Code Online (Sandbox Code Playgroud)
当我们使用它时Ninth(9th)ViewController.NsLog显示:
array= First(1st)ViewController;
Second(2nd)ViewController;
Eight(8th)ViewController;
Ninth(9th)ViewController;
Run Code Online (Sandbox Code Playgroud)
我不知道为什么只有四个视图控制器显示.每当我使用15个视图控制器时.每个视图控制器中都会出现此问题.例如,如果我使用pop形式第十五(15)ViewController到Fifth(5th)ViewController然后相同的问题清单.
NSArray *array = [self.navigationController viewControllers];
NsLog(@"array = %@",array);
array= First(1st)ViewController;
Second(2nd)ViewController;
fourteenth(14th)ViewController;
fifteenth(15th)ViewController;
Run Code Online (Sandbox Code Playgroud)
我想计算ViewControllers的数量,然后弹出到特定的ViewController.
iphone objective-c uinavigationcontroller uipopovercontroller ios
我有一个tabBar+ NavigationViewController.选项卡栏具有带单元格的集合视图(Say view1),单元格中的push seague实现到另一个视图(Say view2).
在view2中我想要一个navBar但没有标签栏.
我试过了
self.tabBarController?.tabBar.hidden = true,
它适用于view2但是当我通过后退按钮返回view1时,选项卡仍然被隐藏(即使在我在viewDidLoad func中添加的view1类中).self.tabBarController?.tabBar.hidden = false
如何让标签栏重新出现在view1中?
我在迅速工作.
uitabbarcontroller uinavigationcontroller pushviewcontroller swift
我目前有一个自定义导航控制器,其中的条形按钮项目只是文本按钮.是否可以保留条形按钮项目的标题,但也可以将它们设置为图像(图标图像+下面的标题).
class NavigationController: UINavigationController
{
var mode: NavigationMode = .Swipe {
didSet {
self.setButtonAttributes()
}
}
private var leftBarButton: UIBarButtonItem!
private var middleBarButton: UIBarButtonItem!
private var rightBarButton: UIBarButtonItem!
private var rightBarButton2: UIBarButtonItem!
override func viewDidLoad()
{
super.viewDidLoad()
}
func configureNavigationItem(navigationItem: UINavigationItem)
{
//Configure the bar buttons text and actions
if (self.leftBarButton == nil) {
self.leftBarButton = UIBarButtonItem(title: "Menu1", style: .Plain,target: self, action: "menu1Pressed:")
}
if (self.middleBarButton == nil) {
self.middleBarButton = UIBarButtonItem(title: "Games", style: .Plain, target: self, action: "gamesPressed:")
} …Run Code Online (Sandbox Code Playgroud) ios ×8
iphone ×4
objective-c ×3
swift ×3
appdelegate ×1
cocoa-touch ×1
ipad ×1
orientation ×1
rotation ×1
swift2 ×1