2013-07-29 22 views
0

我有一个文本框(称为countTotalFieldUniversal),我想改变颜色,当我点击编辑按钮占位符文本。将文字灰色的“编辑按钮”,点击

目前,我的代码是:

- (void)setEditing:(BOOL)flag animated:(BOOL)animated 
{ 
    NSLog(@"setEditing called"); 
    [super setEditing:flag animated:animated]; 
    if (flag == YES){ 
    NSLog(@"Flag is yes"); 
    [countTotalFieldUniversal setValue:[UIColor darkGrayColor] 
          forKeyPath:@"_placeholderLabel.textColor"]; 
    NSLog(@"Color should be grey..."); 
} 
else { 
    // Edit not selected 
    } 
} 

我的控制台打印出的是“国旗是yes”和“颜色应该是灰色的......”但文字不会改变。 我是否正确设置文本?

+0

您可能需要告诉现场才能拿起你的键/值更改为重绘:'[self.countTotalFieldUniversal setNeedsDisplay]'。 –

+0

我补充说,在以前的NSLog权(@“颜色应该是灰色的......”);,但它并没有改变。但是,我不得不[countTotalFieldUniversal setNeedsDisplay]。它不会接受self.countTotalFieldUniversal ...... – AllieCat

+0

我同意你的看法,我需要“刷新”,以表视图。我只是不知道如何... – AllieCat

回答

0

Lakesh主要是对的,我需要reloadData。

我通过增加一个布尔(editClicked)我setEditing功能改变文字颜色:

- (void)setEditing:(BOOL)flag animated:(BOOL)animated 
{ 
    NSLog(@"setEditing called"); 
    [super setEditing:flag animated:animated]; 
    if (flag == YES){ 
    editClicked = true; 
    [tableView reloadData]; 
} 
else { 
    editClicked = false; 
    } 
} 

在我的桌子的的cellForRowAtIndexPath功能,然后我添加了下面的if语句:

//If editClicked is true, change text to grey 
       if (editClicked == true){ 
        [countTotalFieldUniversal setValue:[UIColor darkGrayColor] 
              forKeyPath:@"_placeholderLabel.textColor"]; 
       } 
       else { 
        // Save the changes if needed and change the views to noneditable. 
        [countTotalFieldUniversal setValue:[UIColor blackColor] 
              forKeyPath:@"_placeholderLabel.textColor"]; 
       } 

谢谢每个人(特别是Lakesh和Kyle)的帮助!