我顯示選擇數字的操作表。但現在我想在操作表中顯示默認選定的按鈕。在顯示之前更改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];
更改按鈕文字和背景。
你有什麼錯誤? – Raptor
在操作單中未選擇任何按鈕。 –