使用UIActionSheet更改视图时

使用UIActionSheet更改视图时

本文介绍了使用UIActionSheet更改视图时,工具栏项目消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

UIActionSheet 按钮启动视图时,通过navigationBar后退按钮返回视图时,工具栏仍然可见,但没有任何按钮以前在它上面。自更新到iOS 6后出现此错误,并且仅在模拟器和运行iOS 6的设备上进行测试时发生。如果我注释掉在 UIActionSheet 推送的视图上隐藏工具栏的代码,则会在返回时添加按钮。

When initiating a view from a UIActionSheet button, upon returning to the view via the navigationBar back button, the toolbar while still visible does not have any of the buttons that were previously on it. This error has arisen since updating to iOS 6 and occurs while testing it on the simulator and a device running iOS 6 only. If I comment out the code that hides the toolbar on the view pushed by the UIActionSheet the buttons are added when going back.

我正在 viewWillAppear 中以编程方式创建工具栏项目,并从工具栏中显示 UIActionSheet 通过 self.navigationController.toolbar 进行访问。

I'm making my toolbar items programatically in viewWillAppear and showing the UIActionSheet from the toolbar which I'm accessing via self.navigationController.toolbar.

知道是什么导致了这个问题吗?这是因为iOS 6已经出现,所以有什么变化我需要考虑 viewWillAppear

Any idea what is causing this problem? It's only happened since iOS 6 has come around so is there any changes that I need to take into account regarding viewWillAppear?

这是从actionSheet推送视图的方式:

This is how the view is pushed from the actionSheet:

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {

    if (actionSheet.tag == 2) {

    if (buttonIndex == 0) {

        [self dismissAllTips];

        self.actionNoteAddView= [[self.storyboard instantiateViewControllerWithIdentifier:@"IDActionNoteAddView"] retain];

        actionNoteAddView.note_id = 0;
        actionNoteAddView.iscompleted=0;

        [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"tool_tips"];

        [self.navigationController pushViewController:actionNoteAddView animated:TRUE];

        [actionNoteAddView release];

    }else if(buttonIndex == 1){

        ...

这些是推送视图的视图方法:

These are the view methods for the pushed view:

-(void)viewWillAppear:(BOOL)animated{

    [super viewWillAppear:animated];

    self.navigationItem.hidesBackButton = NO;
    [self.navigationController setToolbarHidden:YES];

    txtcontent.layer.cornerRadius = 10.0f;

}


-(void)viewDidAppear:(BOOL)animated{

    [super viewDidAppear:animated];

}

这些是推送视图的视图的视图方法使用actionSheet:

These are the view methods for the view that pushed the view using the actionSheet:

- (void) viewWillAppear:(BOOL)animated{

    [super viewWillAppear:animated];

    self.navigationItem.hidesBackButton = YES;
    [self.navigationController setToolbarHidden:NO];
    self.navigationController.navigationBarHidden=NO;

    self.navigationController.navigationBar.barStyle = UIBarStyleBlackOpaque;
    self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:0.8 green:0.45 blue:0.2 alpha:1];
    self.navigationController.toolbar.barStyle = UIBarStyleBlackOpaque;
    self.navigationController.toolbar.tintColor = [UIColor colorWithRed:0.8 green:0.45 blue:0.2 alpha:1];

    UIImage *actionButtonImage = [UIImage imageNamed:@"[email protected]"];
    UIBarButtonItem *actionButton = [[UIBarButtonItem alloc] initWithImage:actionButtonImage style:UIBarButtonItemStylePlain target:self action:@selector(actionPressed:)
                                     ];

    UIImage *dashButtonImage = [UIImage imageNamed:@"19-gear.png"];
    UIBarButtonItem *dashButton = [[UIBarButtonItem alloc] initWithImage:dashButtonImage style:UIBarButtonItemStylePlain target:self action:@selector(settingsPressed:)];




    UIBarButtonItem *flexItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
                                                                              target:nil
                                                                              action:nil];

    NSArray *toolitems = [NSArray arrayWithObjects:dashButton, flexItem, actionButton, flexItem, nil];

    [self setToolbarItems:toolitems];

    self.title = @"Dashboard";

    defaultProfile.text = [[NSUserDefaults standardUserDefaults] stringForKey:@"default_profile"];

    BOOL dailyProcess = [[NSUserDefaults standardUserDefaults] boolForKey:@"daily_process"];

    if(dailyProcess){

        [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"daily_process"];
        [[NSUserDefaults standardUserDefaults] synchronize];

        loading = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];

        labelProcess = [[UILabel alloc]initWithFrame:CGRectMake(60, 105, 240, 30)];
        labelProcess.text = @"Processing...";
        labelProcess.backgroundColor = [UIColor clearColor];
        labelProcess.textColor=[UIColor colorWithRed:0.8 green:0.45 blue:0.2 alpha:1];
        [labelProcess setFont:[UIFont systemFontOfSize:20]];

        loading.opaque = NO;
        loading.backgroundColor = [UIColor colorWithWhite:0.0f alpha:0.6f];

        indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
        [indicator setHidesWhenStopped:YES];
        indicator.center = self.view.center;

        [self.view addSubview:loading];
        [self.view addSubview:indicator];

        [self.view addSubview:labelProcess];

        [indicator startAnimating];

    }

}


-(void)viewDidAppear:(BOOL)animated{

    [super viewDidAppear:animated];

    CGRect frame = CGRectMake(157, 365, 10, 10);
    UIView *viewToPointAt = [[UIView alloc] initWithFrame:frame];

    [self.view addSubview:viewToPointAt];

    BOOL willies = [[NSUserDefaults standardUserDefaults] boolForKey:@"tool_tips"];

    if(willies==YES){

        if(popTip == nil) {

            popTip = [[[CMPopTipView alloc] initWithMessage:@"Step 1/3: This is the Action Button. You can create, view and auto-fill notes which are then added to your timeline.(Click for step 2)."] autorelease];
            popTip.delegate = self;

            [popTip presentPointingAtView:viewToPointAt inView:self.view animated:YES];
            popTip.backgroundColor = [UIColor colorWithRed:0.8 green:0.45 blue:0.2 alpha:1];
            popTip.textColor = [UIColor whiteColor];

        }

    }

    [viewToPointAt release];

}


推荐答案

尝试过许多不同的技术,最终通过在一个视图方法中显示它并将其隐藏在下一个方法中进行排序。这是我遇到的最奇怪的错误之一,这不是一个解决方案,但我讨厌没有回答的问题。

Tried a lot of different techniques and eventually sorted it by showing it in one view method and hiding it in the next. It's one fo the strangest bugs I have encountered and this is hardly a fix, but I hate having unanswered questions.

这篇关于使用UIActionSheet更改视图时,工具栏项目消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-04 21:23