0

为什么在分配和初始化一次后添加“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];

在此处输入图像描述

4

1 回答 1

2

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

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

于 2013-05-18T18:38:03.043 回答