ios - UIActionSheet - "init"更改按钮样式

标签 ios objective-c uiactionsheet init

为什么分配和初始化一次后添加“Init”时,UIActionSheet 上“取消”按钮的按钮样式会发生变化?

如果我使用这段代码,它会正确显示:

UIActionSheet *popupQuery = [[UIActionSheet alloc] initWithTitle:@"Photo/Camera" delegate:nil cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Capture - Camera", @"Upload - Photo Library", nil];
popupQuery.actionSheetStyle = UIActionSheetStyleBlackOpaque;
[popupQuery showInView:self.view];

enter image description here




如果我使用此代码(添加了 ...init]),它会显示不正确并且“取消”按钮样式已更改:

UIActionSheet *popupQuery = [[[UIActionSheet alloc] initWithTitle:@"Photo/Camera" delegate:nil cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Capture - Camera", @"Upload - Photo Library", nil] init];
popupQuery.actionSheetStyle = UIActionSheetStyleBlackOpaque;
[popupQuery showInView:self.view];

enter image description here

最佳答案

我假设这是一个好奇的问题(双重“init”没有正当理由)。

第二个 init 很可能会重置第一个 initWithTitle... 中的许多 ivars 设置。最明显的是 cancelButtonIndex 正在重置,因此取消按钮显示为常规按钮。

关于ios - UIActionSheet - "init"更改按钮样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16627580/

相关文章:

iphone - 如何在不同方向设置 UILabel 的位置

ios - 关于 CollectionViewCell

ios - 我可以在多个 tableView 中使用单个原型(prototype)单元格吗?

ios - 如何在 UITextFields 中允许方程式?

ios - 使用 Alamofire 时出现 Heroku "Request Interrupted"错误

iphone - 如何在UIActionSheet中显示自定义 View ?

ios - UIActionsheet 不显示运行 iOS7 的 iPad 上的所有按钮

iphone - UIAlertView 按钮到另一个 View Controller

objective-c - 如何从 iOS 上的 GUI 元素合成图像?

objective-c - 如何在 Objective C 中添加 CSS