如何强制举办活动?

时间:2013-07-01 19:21:50

标签: iphone ios objective-c

我在下载某些控件时遇到问题,我想在按下按钮时更改背景,但似乎按下按钮时,应用程序将不会收听任何事件,直到当前事件在此处完成是我的代码

-(void) menuItem:(RRCircularItem *)item didChangeActive:(BOOL)active {

    [menu progress];
    [menu setBackgroundColor1:[UIColor colorWithPatternImage:[UIImage imageNamed:@"menuabiertoloadingretina.png"]]];
    [menu hideWithAnimationBlock:^{
        self.view.backgroundColor = [UIColor whiteColor];
    }];
    [menu release], menu = nil;
     self.viewCarga.hidden = NO;
    [menu setBackgroundColor1:[UIColor colorWithPatternImage:[UIImage imageNamed:@"menuabiertoloadingretina.png"]]];
    NSLog(@"Item %@ did change state to %d", item.text, active);
    if ([item.text isEqualToString:@"EDITORIALES"]){

        ViewController *viewControler = [[ViewController alloc] initWithNibName:@"EditorialesViewController" bundle:nil];
        [self presentViewController:viewControler animated:YES completion:nil];
        [menu setBackgroundColor1:[UIColor colorWithPatternImage:[UIImage imageNamed:@"menuabiertoloadingretina.png"]]];

    }else if ([item.text isEqualToString:@"GOLES"]){

        GolViewController *viewControler = [[GolViewController alloc] initWithNibName:@"GolViewController" bundle:nil];

        [self presentViewController:viewControler animated:YES completion:nil];
    }else if ([item.text isEqualToString:@"TABLA"]){

        WebViewController *viewControler = [[WebViewController alloc] initWithNibName:@"WebViewController" bundle:nil];

        [self presentViewController:viewControler animated:YES completion:nil];
    }else if ([item.text isEqualToString:@"AUNLI"]){

        AUNLIViewController *viewControler = [[AUNLIViewController alloc] initWithNibName:@"AUNLIViewController" bundle:nil];

        [self presentViewController:viewControler animated:YES completion:nil];
    }else if ([item.text isEqualToString:@"HORARIOS"]){

        HorariosViewController *viewControler = [[HorariosViewController alloc] initWithNibName:@"HorariosViewController" bundle:nil];

        [self presentViewController:viewControler animated:YES completion:nil];
    }

    if (active && ![menu isLabelActive]) {
        [menu setLabelActive:YES];
        [menu setSliderValue:1];
    } else if (!active && [menu isLabelActive]) {
        BOOL hasActive = NO;
        for (int i = 0; i < 6; i++) hasActive |= [menu isItemActive:i];
        if (!hasActive) {
            [menu setLabelActive:NO];
            [menu setSliderValue:0 animated:NO];
        }
    }
}

我想在所有事情之前使用此事件[menu progress];,但它无效。

1 个答案:

答案 0 :(得分:0)

如果我理解嘛,你按下一些按钮就可以保持锁定状态。因为你在主线程中做了一切。这就是为什么你需要使用线程,这样你就可以进行多同步/异步处理,防止你的应用程序中出现锁定。您可以使用NSThread,dispatch或NSOperationQueue ...我喜欢使用 GCD(Grand Central Dispatch)

样品:

    dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void){
    //Background Thread
    dispatch_async(dispatch_get_main_queue(), ^(void){
        //User Interface Updates
    });
});