iOS - 导航标题在按下后退按钮时来自左侧

时间:2014-09-04 04:49:23

标签: ios objective-c uiviewcontroller

在我的应用程序中,当我访问某些视图控制器并触摸导航栏中的“后退”按钮时,生成的视图控件的导航标题看起来是从左上角看来,看起来很丑。

下面显示了这种情况的图片。

enter image description here

我已经以编程方式设置了标题。

有人可以告诉我为什么会发生这种情况以及如何解决这个问题?提前致谢。

这是我的代码:

ViewController B

- (void)viewDidLoad
{
    [super viewDidLoad];

    UILabel * label = [[UILabel alloc] initWithFrame:CGRectMake(0,0,120,45)] ;
    label.textColor = COLOR_TEXT_NAVIGATION_BAR_COLOR;
    label.backgroundColor = [UIColor clearColor];
    label.font = FONT_NAVIGATION_TITLE_BAR;
    label.text = [NSString stringWithFormat:PAGE_TITLE_ADD_SERVICE_PROVIDER];
    self.navigationItem.titleView = label;
    [label sizeToFit];


    UIButton *homeButton = [[UIButton alloc] initWithFrame:CGRectMake(20, 20, 20, 20)];
    [homeButton setImage:[UIImage imageNamed:IMG_HOME_MENU_BUTTON] forState:UIControlStateNormal];
    [homeButton addTarget:self action:@selector(homeMenuAction) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:homeButton];


    accNumTextFiled.delegate=self;

    nameTextFiled.text = addPayee.providerName;
    payLimitTextFiled.text = [NSString stringWithFormat:@"%9.2f", addPayee.paymentLimit];//[NSString stringWithFormat:@"%f",addPayee.paymentLimit];
    descTextFiled.text = addPayee.description;
    catTextFiled.text = addPayee.maincategory;
    subCatTextFiled.text = addPayee.subcategory;

    accNumTextFiled.text = addPayee.paymentAccountNumber;

    [accNumTextFiled setKeyboardType:UIKeyboardTypeNumberPad];

    [self labelCss];

    scrollView.contentSize=CGSizeMake(320,450);
}

ViewController A

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.view.backgroundColor = COLOR_BG_INNER_PAGE_COLOR;


    NSArray *mappingObjArray1  = @[@"providerName",@"description",@"paymentLimit",@"providerCode",@"maincategory",@"subcategory"];

    NSDictionary *queryParams = @{};


    commonRestDataMapping = nil;
    commonRestDataMapping = [[CommonRestDataMapping alloc] init];
    commonRestDataMapping.restDataMappingDelegate = self;
    commonRestDataMapping.servicePath = REST_WEB_SERVICE_ADD_PAYEE_LIST;
    commonRestDataMapping.mappingObjArray = mappingObjArray1;
    commonRestDataMapping.mappingClassString = @"AddPayee";
    commonRestDataMapping.mappingKeyPath = @"data";
    commonRestDataMapping.mappingQueryParams = queryParams;


    [commonRestDataMapping configureRestKit];
    [commonRestDataMapping loadDataArray];


    if ([self respondsToSelector:@selector(edgesForExtendedLayout)])
        self.edgesForExtendedLayout = UIRectEdgeNone;

}


-(void)viewWillAppear:(BOOL)animated{

    [super viewWillAppear:animated];
    [super createNavigationBar:USER_ACCOUNT_PAGE];
    [super setNavihationTitle:PAGE_TITLE_ADD_PAYEE];
    [self.navigationController setNavigationBarHidden:NO animated:animated];

}

AppDelegate.m

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

    //WEB service data initilization
    [[WebServiceUrl getSharedInstance] dataiInitialize];

    [GMSServices provideAPIKey:@"AIzaSyCBfhnMtcmdhJaaqff72PlvJIjBTZpfSu4"];

    NSString* docPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
    NSString* dbPath = [docPath stringByAppendingPathComponent:@"datadb.sqlite"];
    NSFileManager *fm = [NSFileManager defaultManager];

    // Check if the database is existed.
    if(![fm fileExistsAtPath:dbPath])
    {
        // If database is not existed, copy from the database template in the bundle
        NSString* dbTemplatePath = [[NSBundle mainBundle] pathForResource:@"datadb" ofType:@"sqlite"];
        NSError* error = nil;
        [fm copyItemAtPath:dbTemplatePath toPath:dbPath error:&error];
        if(error){
            NSLog(@"can't copy db.");
        } else{
            NSLog(@" copy db.");
        }
    } else {
        NSLog(@"  db exsists");
    }


    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
        UIView *addStatusBar = [[UIView alloc] init];
        addStatusBar.frame = CGRectMake(0, 0, 1024, 20);
        addStatusBar.backgroundColor = [UIColor blackColor]; //change this to match your navigation bar

        [self.window.rootViewController.view addSubview:addStatusBar];
    }



    homeViewController = [[HomeViewController alloc] initWithNibName:@"HomeViewController" bundle:nil];
    UINavigationController *myNav1=[[UINavigationController alloc] initWithRootViewController:homeViewController];


    UIImage *navBackgroundImg = [UIImage imageNamed:@"aa1.png"];

    [myNav1.navigationBar setBackgroundImage:navBackgroundImg forBarMetrics:UIBarMetricsDefault];//iOS 5 only

    // Override point for customization after application launch.
    self.viewController = myNav1;
    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];



    return YES;
}

- (void)transitionToViewController:(UIViewController *)viewController
                    withTransition:(UIViewAnimationOptions)transition
{
    [UIView transitionFromView:self.window.rootViewController.view
                        toView:viewController.view
                      duration:0.35f
                       options:transition
                    completion:^(BOOL finished){
                        self.window.rootViewController = viewController;
                    }];
}

0 个答案:

没有答案