2014-03-28 34 views
0

我顯示選擇數字的操作表。但現在我想在操作表中顯示默認選定的按鈕。在顯示之前更改UIActionsheet按鈕文本和背景

代碼:

他們是沒有錯誤,但actionsheet顯示並沒有選擇任何按鈕:前顯示

- (void)willPresentActionSheet:(UIActionSheet *)actionSheet 
{ 
    for (UIView *subview in actionSheet.subviews) { 

     if ([subview isKindOfClass:[UIButton class]]) { 

      UIButton *button = (UIButton *)subview; 

      [button setTitleColor:[UIColor redColor] forState:UIControlStateSelected]; 

      if ([button.titleLabel.text isEqualToString:@"5"]) { 

       button.selected = true; 
       [button setBackgroundColor:[UIColor blueColor]]; 

      } 
     } 
    } 
} 

編輯

UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Select Number" 
                  delegate:self 
                cancelButtonTitle:@"Cancel" 
destructiveButtonTitle:nil otherButtonTitles:@"0",@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10", nil]; 


[actionSheet showInView:self.view]; 

更改按鈕文字和背景。

+0

你有什麼錯誤? – Raptor

+0

在操作單中未選擇任何按鈕。 –

回答

1

這裏是解決

+0

如何更改標籤顏色? –

+0

請採取以上更新的代碼 – Thukaram

0

UIActionSheet不具備選定按鈕的概念。一個模態視圖控制器可能更適合。或者如果你在iPad上,你可以在裏面使用UIPopoverControllerUITableView