2011-07-06 26 views
2

所以我有一個tableview與8個單元格包含8 uitextfields作爲每個單元格的子視圖。它基本上就像用戶需要填寫的表單,而用戶開始輸入時我需要一些效果。UITableViewCell亮點和影響

TextFieldDidBeginEditing方法被調用時,我想要相應的UITableViewCell被突出顯示,並且所有其他UITableViewCells被排序爲'Dimmed'。這種效果使得用戶專注於他正在輸入的特定文本字段,並且我試圖在我的代碼中實現這一點。

這可能嗎?我很感激,如果有人能幫助我這個效果!

回答

4

在這裏你去:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    NSArray*cells = [_regTable visibleCells]; 

    UITableViewCell*currentcell = [_regTable cellForRowAtIndexPath:indexPath]; 

    for (UITableViewCell*cell in cells) 
    { 
     if ([cell isEqual:currentCell] == NO) //You'll have to think on how to distinguish a selected cell from an unselected one - if you go the default way then that's how its done 
     { 
      [UIView beginAnimations:nil context:NULL]; 
      [UIView setAnimationDuration:0.5]; 
      cell.alpha = 0.5; 
      [UIView commitAnimations]; 
     } 
     else 
     { 
      [UIView beginAnimations:nil context:NULL]; 
      [UIView setAnimationDuration:0.5]; 
      cell.alpha = 1.0; 
      [UIView commitAnimations]; 
     } 

    } 
} 
+0

嗯。非常感謝輸入。我可以理解'alpha'的上下文,並且似乎是一個很好的開始。從你的代碼,這會影響整個uitableviewcell? – Legolas

+0

'UITableViewCell'是一個'UIView'。所以你可以去'cell.alpha'並設置所需的值,但我不鼓勵這樣做,因爲它會對單元格產生一些瘋狂的影響,因爲它看起來有點奇怪。 :P – Pripyat

+0

剛剛添加了一個不錯的'UIView'淡入淡出動畫,所以它不那麼生澀。試一試! – Pripyat