标签: uinavigationcontroller

UITabBarController:以编程方式切换到不同的视图控制器

在我的iPhone应用程序中,要恢复以前查看的选项卡,在启动时我设置了setSelectedIndex :(也尝试过setSelectedViewController:根据文档但无效)

这适用于iPhone OS 3.0 - 但是在OS 2.x上,所选索引大于3(前4个选项卡)不会切换到所需视图.Apple在此处记录了这一点:http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UITabBarController_Class/Reference/Reference.html#//apple_ref/occ/instp/UITabBarController/selectedViewController

我想知道是否可以切换到iPhone OS 2.x下的视图控制器?任何帮助表示赞赏.

顺便提一下我的模拟器设置索引大于3会引发错误(对于iPhone OS 2.x) - 所以我把它包装在@try {..} @catch(id ..){}块中 - 希望这个技术可以帮助某人.

iphone restore objective-c uitabbarcontroller uinavigationcontroller

8
推荐指数
2
解决办法
3万
查看次数

子类化UINavigationBar ...如何在UINavigationController中使用它?

我想子类化UINavigationBar(设置自定义背景图像和文本颜色)并将其用于我的应用程序中的所有导航栏.查看UINavigationController的API文档,看起来navigationBar是只读的:

@property(nonatomic,readonly)UINavigationBar*navigationBar

有没有办法在我的UIViewControllers中实际使用自定义UINavigationBar?我知道其他应用程序已经完成了自定义导航栏,如flickr:

http://img.skitch.com/20100520-bpxjaca11h5xne5yakjdc2m6xx.png

这是我的UINavigationBar子类:

#import <UIKit/UIKit.h>

@interface MyNavigationBar : UINavigationBar <UINavigationBarDelegate> {

}

@end
Run Code Online (Sandbox Code Playgroud)

实施

#import "MyNavigationBar.h"

@implementation MyNavigationBar

- (id)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        // Initialization code
    }
    return self;
}

- (void)drawRect:(CGRect)rect {
    // override the standard background with our own custom one
    UIImage *image = [[UIImage imageNamed:@"navigation_bar_bgd.png"] retain];
    [image drawInRect:rect];
    [image release];
}

#pragma mark -
#pragma mark UINavigationDelegate Methods

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated{
    // use the title of the passed …
Run Code Online (Sandbox Code Playgroud)

iphone uinavigationbar uinavigationcontroller subclassing

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

转到推动可见视图控制器的视图控制器

我有一个应用程序有一个UINavigationController推进UITabBarController视图.这UITabBarController有四个选项卡,其中一个显示自定义UIViewController,一个实例EventInformationViewController.此自定义视图控制器中的按钮依次将另一个自定义视图控制器推EventRatingAddViewController入视图.此视图控制器中的操作应调用EventInformationViewController实例中的方法.以下代码使应用程序崩溃:

// get the index of the visible VC on the stack
int myIindex = [self.navigationController.viewControllers indexOfObject:self.navigationController.visibleViewController];
// get a reference to the previous VC
EventInformationViewController *prevVC = (EventInformationViewController *)[self.navigationController.viewControllers objectAtIndex:myIindex - 1];
[prevVC performSelector:@selector(rateCurrentEvent:)];
Run Code Online (Sandbox Code Playgroud)

我认为viewControllers属性在导航堆栈上保留了所有VC的数组,因此当前可见的减去索引的索引应指向将当前可见VC推入视图的VC.相反,它似乎指向我UITabBarController:

-[UITabBarController rateCurrentEvent:]: unrecognized selector sent to instance
Run Code Online (Sandbox Code Playgroud)

具体是什么,更重要的是,如何获得指向VC的指针,该指针将当前可见的VC推入视图?

编辑:我最终创建了一个委托协议,EventRatingAddViewController并指定EventInformationViewController为委托.这很好用 - 我仍然认为应该有一种方法来通过导航堆栈访问推送VC.

iphone uinavigationcontroller

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

UINavigationController上的自定义titleView动画设置不正确

我可能在这里做错了,因为这看起来有点愚蠢.
我在我的UINavigationController上设置了一个自定义titleView(以UILabel的形式),在每个页面上都是相同的.为了实现这一点,我在我的app delegate中创建了一个函数来正确显示标签.然后我将其推送到导航堆栈后,在任何子视图上调用此函数.
这是代码(可能比我的解释更有意义):

//In MyAppDelegate.m:
- (void)showTitleForNavigationController:(UINavigationController*) navController {
    UILabel *label = [[UILabel alloc] init];
    // set up label attributes
    // ...
    [label sizeToFit]; //without this line my label won't show at all
    [navController.navigationBar.topItem setTitleView:label];
    [label release];
}

// In SomeViewController.m, when pushing another controller onto the stack:
    UIViewController *otherViewController = //initialize other view controller;
    [self.navigationController pushViewController:otherViewController animated:YES];
    [(MyAppDelegate*)[[UIApplication sharedApplication] delegate] showTitleForNavigationController:otherViewController.navigationController];
Run Code Online (Sandbox Code Playgroud)

我的问题是,当我将下一个视图控制器推入堆栈,并且新控制器平滑地滑动时,在动画的整个持续时间内,标签粘贴在左上方,然后在动画结束后最终捕捉到位.它看起来很奇怪和丑陋.如何正确设置标签,使其从下一个视图平滑滑动?当然,这很简单,我很想念......

animation cocoa-touch uinavigationcontroller titleview

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

在许多UIVIewControllers之间传递变量

在我的iPhone应用程序中,有一个设置助手,可以帮助用户输入大量数据.它基本上是一个UINavigationController,里面有很多UIViewControllers.现在,在某个时刻,我想访问用户在他看到的第一个UIViewController中输入的变量.我可以使用setter方法在每个UIViewController之间传递变量,但我想有一种更简单的方法.

iphone xcode objective-c uiviewcontroller uinavigationcontroller

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

隐藏导航栏,具体取决于视图控制器的显示方式

我在其中一个选项卡中有一个带有导航控制器的标签栏.目前,导航控制器的根视图没有显示导航栏,并且可以很好地动画到子视图中

- (void)viewDidLoad {
   ...
   [self.navigationController setNavigationBarHidden:YES animated:NO];
   ...
}
Run Code Online (Sandbox Code Playgroud)

和

- (void)viewWillAppear:(BOOL)animated {
    [self.navigationController setNavigationBarHidden:YES animated:YES];
}

- (void)viewWillDisappear:(BOOL)animated {
    [self.navigationController setNavigationBarHidden:NO animated:YES];
}
Run Code Online (Sandbox Code Playgroud)

但是当然更改选项卡会启动该viewWillAppear功能,因此当我返回到根视图时,导航栏会滑落,而不是仅仅不在那里.

有没有办法可以隐藏根视图上的导航栏而不动画它除了从导航堆栈上的子视图出现时?

cocoa-touch uitabbarcontroller uinavigationcontroller ios

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

viewWillAppear vs Viewdidload ios

使用iOS导航应用程序的代码时,我遇到了麻烦:

我在哪里可以为UITableView设置方法"initdata"?在viewWillAppear或viewDidLoad?

请帮帮我.

uitableview uinavigationcontroller ios

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

在iOS应用程序中采用侧边菜单.查看控制器结构问题

我正在设计一个旨在具有以下导航结构的应用程序:我需要一个带有"注册"和"登录"按钮的欢迎视图,因为大多数应用程序具有:

iPhone_welcome

此视图不显示任何导航栏,因为它似乎是常见的事情.如果点击"登录",则会以模态方式显示登录视图:

iPhone_signIn

如果点击"注册",欢迎视图会导航到请求用户输入以创建帐户的表单:

iPhone_signUp

然后,一旦用户登录并进入应用程序,我希望它具有类似于Facebook,YouTube或Spotify的侧边菜单:

iPhone_facebook

作为中心小组a UINavigationController.左侧面板我觉得它通常是'UIViewController'......

关键是,我不知道rootViewController我的应用程序应该是什么,以及我应该具有什么样的视图控制器层次结构.我想过几个可能性:

1)作为rootViewControllera UINavigationController,按下隐藏导航栏的欢迎视图(可能吗?),如果需要,可以显示"登录"视图或按"注册"视图.一旦用户登录,从rootViewControllera,即a 弹出这些视图UINavigationController,然后在这样的导航控制器中推入管理侧边菜单内容的自定义视图控制器.

2)作为rootViewController侧面菜单自定义视图控制器,并设置为其中央面板a UINavigationController.按下欢迎视图等,无需为左/右面板设置任何视图控制器,然后当用户登录时,从中央面板弹出这些视图UINavigationController,按下相应的视图,然后设置左/右面板

我希望我已经解释过了.也许有另一种更好的方法来处理这种情况.有人实现了这样的应用程序吗?我需要这个问题的帮助,而且我也很感激被推荐一个自定义库/控件提供侧面菜单的东西来自使用过它的人,它易于使用和自定义.我知道它们有很多(例如MMDrawerController,JASidePanels),但是我想从其中一个开发了应用程序的人那里获得一些意见.

注意:我也需要支持iPad和iOS 5+

非常感谢

navigation sidebar uinavigationcontroller ios rootview

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

当视图标题很长时,iOS7 UINavigationBar中显示"back"文本

在我的应用程序中,我需要将以前的viewController标题显示给当前的viewController后标题.

它在iOS6中完美运行.

在iOS7中,自动显示"back"标题,而不是之前的viewController标题.

如何解决iOS7中的问题?

objective-c uinavigationbar uinavigationcontroller ios7

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

Swift:取消UIPercentDrivenInteractiveTransition?

这是我的第一个iOS开发,因此我正在使用这个小项目来了解系统的工作原理以及语言(swift)的工作原理.

我正在尝试制作类似于Android应用程序和一定数量的iOS应用程序的抽屉菜单.

我发现本教程很好地解释了如何操作以及它是如何工作的:这里

现在,因为我使用带有show的NavigationController,我必须修改它的完成方式.

我将UIViewControllerTransitioningDelegate交换为UINavigationControllerDelegate,因此我可以覆盖navigationController函数.

这意味着我可以把抽屉拿出来并解雇它.它适用于按钮或手势.我的问题如下:如果我没有完成将抽屉拖得足够远以达到阈值并完成动画,它将被取消并隐藏.这一切都很好但是当发生这种情况时,没有调用dismiss函数意味着我在PresentMenuAnimator中放置的快照仍然在所有层的前面,即使我可以与后面的内容进行交互,我仍然被困在那里它.

如何通过NavigationController捕获解雇或取消?那可能吗 ?

交互者:

import UIKit


class Interactor:UIPercentDrivenInteractiveTransition {
    var hasStarted: Bool = false;
    var shouldFinish: Bool = false;

}
Run Code Online (Sandbox Code Playgroud)

MenuHelper:

import Foundation
import UIKit

enum Direction {
    case Up
    case Down
    case Left
    case Right
}

struct MenuHelper {
    static let menuWith:CGFloat = 0.8;
    static let percentThreshold:CGFloat = 0.6;
    static let snapshotNumber = 12345;

    static func calculateProgress(translationInView:CGPoint, viewBounds:CGRect, direction: Direction) -> CGFloat {
        let pointOnAxis:CGFloat; …
Run Code Online (Sandbox Code Playgroud)

delegates uinavigationcontroller ios swift

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