在我的iOS 8應用程序中,我使用UIActionSheet。我試圖在willPresentActionSheet
委託方法中更改按鈕標題的顏色,但它不會將按鈕識別爲其子視圖。UIActionSheetdelegate沒有得到子視圖
我構造UIActionSheet
這樣的:
UIActionSheet *popup = [[UIActionSheet alloc] initWithTitle:@"Select an Option" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles: nil];
popup.tag = 2;
[popup addButtonWithTitle:@"Add Tag To Chat"];
[popup addButtonWithTitle:@"Remove Tag From Chat"];
[popup addButtonWithTitle:@"Terminate"];
[popup addButtonWithTitle:@"Cancel"];
[popup showInView:self.view];
代表是:
- (void)willPresentActionSheet:(UIActionSheet *)actionSheet
{
NSLog(@"%d",[actionSheet.subviews count]);
for (UIView *subview in actionSheet.subviews) {
if ([subview isKindOfClass:[UIButton class]]) {
UIButton *button = (UIButton *)subview;
[button setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
}
}
}
按鈕被示出,我可以點擊和動作執行。但它說count = 0.爲什麼?
操作表不像iOS 7中那樣可定製。嘗試任何開源替換方法,因爲您只是試圖破解自己的方式,可能會使其在更多操作系統版本中崩潰。 – Shubhank
在iOS 8下,'UIActionSheet'是用新的'UIAlertController'實現的,它是完全不同的,不能以任何方式定製。您需要創建或使用支持所需內容的自定義實現。 – rmaddy
[這是最好的(和可定製的)開源行動表之一](https://github.com/fastred/AHKActionSheet) – MendyK