标签: uinavigationcontroller

为每个屏幕定制NavigationController的后退按钮

我一直在尝试子类化UINavigationController类来修改背景图像,导航栏大小,后退按钮,tittle字体等内容.经过几个小时和大量的阅读后,我明白我不应该继承UINavigationController类...

我想具体设计并将该设计转移到使用我的自定义NavigationController的所有屏幕......

到目前为止,我没有为此提供任何优雅的解决方案,大多数解决方案都基于配置仅在下一个屏幕中显示的内容(下一个视图).

我怎样才能做到这一点?也许使用类别?提前致谢.

iphone objective-c uinavigationbar uinavigationcontroller ios

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

如何用backBarButtonItem替换leftBarButtonItem

在Interface Builder中,我创建了一个视图,作为Storyboard的一部分,过去只在一个不同的上下文中显示(作为UITabBarController的视图).

现在我想重用此视图作为UINavigationController视图的一部分,但通常可以正常工作.唯一的问题是在IB中,我将一个按钮设置为leftBarButtonItem.因此,当我在导航控制器的堆栈上推送相同的视图Controller时,它将不再自动放置backBarButtonItem.

有没有一种标准的方法来处理这种情况?我是否必须自己删除按钮,具体取决于viewcontroller是否是UITabBarController或UINavigationController的一部分?我想在IB中保留按钮.因此,在viewDidDisappear上将leftBarButtonItem设置为nil,例如只有一些帮助.这确实正确地显示了backBarButtonItem,但是当用户返回到该屏幕时,我将不得不再次手动设置leftBarButtonItem.

uinavigationcontroller ios

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

设置UINavigationController的标题

我有一个UITabBarController设置5个选项卡,在屏幕上放置一个实例ViewController,我放置UINavigationController:

UINavigationController *nc = [[UINavigationController alloc]init];
[self.view addSubview:nc.view];
Run Code Online (Sandbox Code Playgroud)

它完美地工作(选项卡和导航栏),但是将标签的标题设置到栏上时出现问题.

我试图把self.title = @"something";在- (id)init和- (void)viewDidLoad-第一次什么也没做,第二个改变了我的一个标签,而不是导航栏的标题.

我的问题是:在哪里放置我的代码,或者我应该做出哪些改变?

title uinavigationcontroller ios

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

UIPopoverController中的UINavigationController:设置标题

我正在尝试显示UINavigationController内部a UIPopoverController,但由于某种原因我无法设置标题.

SearchViewController *searchView = [[[SearchViewController alloc] init] autorelease];

UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:searchView];
[popover presentPopoverFromBarButtonItem:_searchBarButton permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
Run Code Online (Sandbox Code Playgroud)

我尝试过改变它 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
    // Change the title
    UILabel *label = [[[UILabel alloc] initWithFrame:CGRectZero] autorelease];
    label.backgroundColor = [UIColor clearColor];
    label.font = [UIFont boldSystemFontOfSize:20.0];
    label.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.5];
    label.textAlignment = UITextAlignmentCenter;
    label.textColor = [UIColor whiteColor];
    label.text = @"Print / Email";
    [label sizeToFit]; …
Run Code Online (Sandbox Code Playgroud)

iphone uinavigationcontroller uipopovercontroller ios

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

导航栏和表格视图之间的黑条显示在iOS 6上

自从我开始使用iOS 6后,我似乎遇到了一个问题,这在使用iOS 5时没有出现.起初,我认为它可能只是一个模拟器错误,但是自从今天在我的iPhone 5上测试它,我可以看到它不只是在模拟器中.

我正在以编程方式创建所有内容 - 我似乎更喜欢这样做(我认为这是因为我的HTML/CSS背景!) - 但我仍然是Objective-C的新手,我找不到完整的示例如何以编程方式设置导航控制器/表视图,所以我把它放在我能找到的信息块中,因此,我可能会做一些根本错误的事情.但是,它在iOS 5上完美运行(并且仍然有效).

问题是我在导航栏和表视图之间有一个黑条,但奇怪的是,如果我按下一个视图并返回到原始视图,该条消失,并且在我完全重启之前不再出现该应用程序.

下面的图片是启动时的应用程序(1),因为我正在推动(2)中的视图,以及我回到它之后的初始视图(3):

这就是我的代码:

AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    RootViewController *rootController = [[RootViewController alloc] init];
    self.window.rootViewController = rootController;

    self.navigationController = [[UINavigationController alloc] initWithRootViewController:rootController];
    [self.window addSubview:navigationController.view];

    [self.window makeKeyAndVisible];

    NSLog(@"Window frame: %@", NSStringFromCGRect(self.window.frame));

    return YES;
}
Run Code Online (Sandbox Code Playgroud)

RootViewController.m

- (void)loadView
{
    self.title = @"Title";

    self.tableView = [[UITableView alloc] initWithFrame:[[UIScreen mainScreen] bounds] style:UITableViewStylePlain];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.view = self.tableView;

    NSLog(@"tableView frame: %@", NSStringFromCGRect(self.tableView.frame)); …
Run Code Online (Sandbox Code Playgroud)

objective-c uitableview uinavigationcontroller ios ios6

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

iPhone XCode UITabBarController和UINavigationController

当我收到以下错误时,我正在尝试更新我的应用程序以在iPhone 5上工作:

Terminating app due to uncaught exception 'UIViewControllerHierarchyInconsistency',
reason: 'A view can only be associated with at most one view controller at a time!
View <UITableView: 0x88fbe00; frame = (0 20; 320 548); clipsToBounds = YES; opaque = NO; 
autoresize = W+H; gestureRecognizers = <NSArray: 0x8395940>; layer = <CALayer: 0x8395350>;
contentOffset: {0, 0}> is associated with <UIViewController: 0x83967d0>. Clear this
association before associating this view with <UIViewController: 0x8381220>.'
Run Code Online (Sandbox Code Playgroud)

我正在运行XCode版本4.5,这从未发生过.我试图按照这个问题中的步骤进行操作.这就是我的MainWindow.xib的样子:

的MainWindow.xib

我做错了什么,我该如何解决?

iphone uinavigationcontroller ios

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

ios6中的方向问题

我在我的应用程序中使用UINavigationController,我的第一个控制器叫做A,它只对portrite有严格要求,我的A控制器中有一个按钮.一旦我点击按钮,我就会在另一个名为B的视图控制器上创建实例.在为BI创建实例后,使用以下方法进行模态呈现

[self presentViewController:BInstance animated:YES completion:^{
            NSLog(@"completed");
        }];
Run Code Online (Sandbox Code Playgroud)

我的B控制器能够支持所有方向,这是预期的,直到ios5.1及更早版本.现在我正在尝试使用Xcode4.5在ios6上运行我的项目它没有被轮换我期待解决这个问题我发现了一些关于shouldAutorotateToInterfaceOrientation 的博客:方法从最新的ios6中被弃用了.我也用过替代品

-(BOOL)shouldAutorotate{
    return YES;
}
-(NSUInteger)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskAll;
}
Run Code Online (Sandbox Code Playgroud)

但仍然没有太多预期的结果.

问题:什么使我的B控制器适用于所有方向,即使我的父A只适用于portrite.

在此先感谢您对此有用的所有建议/建议.

uinavigationcontroller ipad presentmodalviewcontroller ios6

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

UIAppearance和UINavigationBar控制器

我有我的UIBarButtonItems和我的UINavigationBar的背景图片.我正在尝试使用UIAppearance来自定义所有这些,具体如下:

    [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"navbar.png"] forBarMetrics:UIBarMetricsDefault];
    [[UIBarButtonItem appearance] setBackgroundImage:[UIImage imageNamed:@"navbar_btn.png"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
Run Code Online (Sandbox Code Playgroud)

而且效果很好.唯一的问题是UINavigationBar上的默认后退按钮仍然使用标准的iOS背景颜色/图像.当我在[UINavigationBar外观]上设置TintColor时,它会改变颜色,但只需要一个UIColor.

是否可以设置默认导航后退按钮图像(无需手动更改每个viewcontroller)或将图像转换为UIColor?

谢谢!

更新:答案如下

显然,UIBarButtonItem有一个单独的函数用于后退定制.我必须根据navbar_btn.png为后退按钮创建另一个图像并使用以下方法设置它:

[[UIBarButtonItem appearance] setBackButtonBackgroundImage:backButtonImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
Run Code Online (Sandbox Code Playgroud)

objective-c uinavigationcontroller ios uiappearance

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

UINavigatorController popViewController:动画显示iOS 5.1中的奇怪行为,但不显示iOS 6中的行为

我发现了一些我在iOS应用程序中无法解释的奇怪行为.

我正在使用嵌入在UITabBarController子类中的标准UINavigationController.

当我在NavigationController上推送一个ViewController时,动画就可以了.但是当在Landscape中弹出ViewController时,弹出动画从屏幕顶部发生到下端,而不是预期的从右到左标准行为.

更奇怪的是,TabBar包含在动画过渡中,在纵向模式下也不是这样.

这只发生在iOS 5设备上,目前我还不知道为什么会发生这种情况.

uinavigationcontroller ios5 popviewcontrolleranimated

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

pushViewController无法在iOS 5上运行(在iOS 6上运行正常)

我有一个UINavigationController,在屏幕上显示几个按钮.他们都只是使用这条线:

myViewController *newView = [[myViewController alloc] initWithNibName:@"myViewController"
                                                                          bundle:nil];
[[self navigationController] pushViewController:newView animated:YES];
Run Code Online (Sandbox Code Playgroud)

转换到下一个视图.我有一个这样的视图控制器但是只会在iOS 5上导致此行崩溃.它在iOS 6上工作得非常好.我很困惑.崩溃没有真正的细节.这是一个强调main.m行的SIGABRT:

exitStatus = UIApplicationMain( argc, argv, nil, NSStringFromClass([ApplicationDelegate class]));
Run Code Online (Sandbox Code Playgroud)

我没有线索...

iphone uinavigationcontroller sigabrt ios

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