为什么分配和初始化一次后添加“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];
如果我使用此代码(添加了 ...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];
最佳答案
我假设这是一个好奇的问题(双重“init”没有正当理由)。
第二个 init
很可能会重置第一个 initWithTitle...
中的许多 ivars 设置。最明显的是 cancelButtonIndex
正在重置,因此取消按钮显示为常规按钮。
关于ios - UIActionSheet - "init"更改按钮样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16627580/