2013-07-01 43 views
-4

我遇到了一些问题,我下载了一些控件,我想在按下按钮时更改背景,但似乎按下按钮后,应用程序将不会听任何事件,直到当前事件完成为止我的代码如何强制一个事件?

-(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];,但它不起作用。

+2

你问UI组件,我们不知道。此外,很明显,您在抓住其他obj-c概念时遇到问题,例如MRC中对象的所有权。你的问题可能是由于iOS事件的误解造成的。 – Sulthan

回答

0

如果我明白那么,你按下一些按钮,你保持lock.Its因为你正在做主线程中的一切。这就是为什么你需要使用线程,这样你会做多重同步/异步进程,防止你的应用程序锁。您可以使用NSThread,发送或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 
    }); 
}); 
+0

它工作!谢谢 – atrik

+0

@atrik没问题;) –