2013-04-10 89 views
0

这可能是一个简单的问题,但我无法弄清楚我缺少什么。如何在调用方法目标之前设置NSString c

在ViewControl.h我宣布的UIColor

@property (nonatomic, strong) UIColor * myColor; 

在ViewControl.m我有做一些事情,并返回新的UIColor

@synthesize myColor = _myColor; 

在viewDidLoad方法

- (void)viewDidLoad 
{ 
    myColor = [UIColor RedColor]; 
} 

-(void) ShowColorPopUpView 
{ 
    if (!self.wePopoverController) 
    { 

     ColorViewController *contentViewController = [[ColorViewController alloc] init]; 
     contentViewController.delegate = self; 
     self.wePopoverController = [[WEPopoverController alloc] initWithContentViewController:contentViewController]; 
     self.wePopoverController.delegate = self; 
     self.wePopoverController.passthroughViews = [NSArray arrayWithObject:self.navigationController.navigationBar]; 

     [self.wePopoverController presentPopoverFromRect:self.tvTweetDetails.frame 
                inView:self.view 
           permittedArrowDirections:(UIPopoverArrowDirectionUp|UIPopoverArrowDirectionDown) 
               animated:YES]; 

    } else 
    { 
     [self.wePopoverController dismissPopoverAnimated:YES]; 
     self.wePopoverController = nil; 
    } 
} 

-(void) colorPopoverControllerDidSelectColor:(NSString *)hexColor 
{ 
    _myColor = [GzColors colorFromHex:hexColor]; 
    [self.view setNeedsDisplay]; 
    [self.wePopoverController dismissPopoverAnimated:YES]; 
    self.wePopoverController = nil; 
} 
- (UIColor *) returnColor 
{ 
    return _myColor; 
} 

的方法我的问题从这里开始:我有两种方法来更改textview字体和背景颜色

- (IBAction)btnFontColorPopUpMenu:(id)sender 
{ 
    [self ShowColorPopUpView]; 
    tvTweetDetails.textColor = [self returnColor]; 
} 
- (IBAction)btnTextViewBackGroundColor:(id)sender 
{ 
    [self ShowColorPopUpView]; 
    tvTweetDetails.backgroundColor = [self returnColor]; 
} 

现在的问题是,当我调用它返回的方法时,它返回RED,如果我再次调用它,它将返回BlackColor。

如何调用该方法并将Color更改为新的,然后将其返回。我想直接得到黑色。

我想先执行方法然后返回颜色,但是会发生什么是在执行方法之前分配颜色。

我希望我把问题弄清楚了。

+0

add'myColor = [UIColor RedColor];'in'changeMycolor'方法。 – 2013-04-10 16:18:15

+0

你究竟想在这里做什么? – bdesham 2013-04-10 16:18:18

+0

它已经添加..对不起,我想写myColor而不是myString。 @AnoopVaidya – iMubarak 2013-04-10 16:23:10

回答

1

好的,我会采取一个重击此。

我怀疑你正在做一些presentViewController: ...方法在你的换色方法。这很好,但它有影响。您在中调用的方法在该演示期间继续执行。这意味着它可能会返回,等等。

这就是委托人的概念出现的地方。您可能会从这里稍稍重构数据流。

我建议什么(如果我对一个颜色选择器UI的演示正确的),就是你做如下修改:

  1. 创建@protocol ColorPickerDelegate有一个方法:-(void) userChoseColor:(UIColor *) color
  2. 添加@property (weak) id<ColorPickerDelegate> delegate到你的颜色选择器视图控制器
  3. 让您有个VC实现该协议
  4. 里面的委托方法,将您的本地地产
  5. 实现当地特性的自定义设置器,并且每当颜色改变时更新背景颜色
+0

首先感谢您的解释。正如我所说的颜色选择器工作正常,它返回我选择的颜色并将其分配给myColor。我的问题是changeTextViewBackGround方法首先将myColor分配给TextView背景颜色,然后执行changeMyColor ..我想先做适当的调用changeMyColor,然后分配TextView颜色@ctrahey – iMubarak 2013-04-10 17:24:30

+0

@iMubarak:我认为您需要发布更多的代码,以便我们可以实际上看到你想描述的控制流程。 – drewmm 2013-04-10 17:30:41

+0

我编辑问题并添加Code @drewmm – iMubarak 2013-04-10 17:43:38