如果单击工具栏上的按钮,我想显示弹出窗口。我正在使用ios 8 SDK。
我使用下面的代码执行相同操作,但现在我想从中删除标题。
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:[appDelegate encTitle]
delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil
otherButtonTitles:@"Add Bookmark", @"Cancel",nil];
actionSheet.actionSheetStyle = UIActionSheetStyleDefault;
actionSheet.cancelButtonIndex = 1; // make the second button red (destructive)
[actionSheet showInView:self.view]; // show from our table view (pops up in the middle of the table)
[actionSheet release];
如果我像这样使用initWithTitle:@""然后标题栏也出现在弹出窗口中。
目前就像是图片
希望实现这样的目标
请帮我解决问题。
按照sweetAngel的建议使用UIalertviewController后,它会在iPhone 4s中出现......请帮助在所有设备中正确显示它。
答案 0 :(得分:1)
在iOS 8中,您不仅要定义不使用retain
/ release
,而且为了呈现操作表,您应该使用UIAlertController
,因为不推荐使用UIActionSheet
。这是一个例子:
UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:@"Evacuate Building!" message:@"" preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction *destructiveAction = [UIAlertAction actionWithTitle:@"Kick through door" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
// destructive action completion
}];
UIAlertAction *defaultAction = [UIAlertAction actionWithTitle:@"Walk calmly" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
// default action completion
}];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Do nothing" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
// cancel action completion
}];
[actionSheet addAction:destructiveAction];
[actionSheet addAction:defaultAction];
[actionSheet addAction:cancelAction];
[self presentViewController:actionSheet animated:YES completion:nil];
答案 1 :(得分:1)
如果您使用的是iOS 8,那么您可以试试这个:
UIAlertController *alert1 = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction* ok = [UIAlertAction actionWithTitle:@"Add Bookmark" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
// Your code for bookmark
[alert1 dismissViewControllerAnimated:YES completion:nil];
}];
UIAlertAction* cancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
[alert1 dismissViewControllerAnimated:YES completion:nil];
}];
[alert1 addAction:ok];
[alert1 addAction:cancel];
[self presentViewController:alert1 animated:YES completion:nil];