我对以下实例所需的对象所有权模式有些不清楚.当我的UIViewController将弹出控制器,操作表或其他视图控制器呈现为模态时,我是否需要挂起对该子控制器的保留引用,直到它被解除为止?
换句话说,以下几行代码是否有效地"转移"了所有权?
[aPopoverController presentPopoverFromBarButtonItem:someButtonItem permittedArrowDirections:UIPopoverArrowDirectionAny animated:NO];
[anActionSheet showFromBarButtonItem:someButtonItem animated:NO];
[aViewController presentModalViewController:someOtherViewController animated:YES];
Run Code Online (Sandbox Code Playgroud)
有人能指出我关于这个主题的明确文件吗?
我有这个问题:这是我的代码:
UIActionSheet *popupQuery = [[UIActionSheet alloc] initWithTitle:@"Share the race" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Send with mail" otherButtonTitles:nil];
popupQuery.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
[popupQuery showInView:self.view];
[popupQuery release];
Run Code Online (Sandbox Code Playgroud)
一切似乎都没问题,2个按钮显示正确,"发送邮件"按钮没问题,但取消仅在上方抓住点击...这里有一个说明情况的镜头:

我该怎么解决这个问题?
谢谢:)
我在ViewController中创建了一个UIActionSheet.我还添加了代码来捕获UIKeyboardWillShowNotification和UIKeyboardWillHideNotification通知.
我的问题是当我解雇时,我得到两个通知键盘隐藏并再次显示.有人可以告诉我如何预防这个问题?它只发生在iOS 7中并使用SDK 7构建
更新一些代码:
在viewDidLoad中,我初始化一个按钮,当触摸按钮时,将显示动作表.
- (void)viewDidLoad
{
[super viewDidLoad];
UIButton* button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = CGRectMake(10, 50, 100, 30);
[button setTitle:@"Open menu" forState:UIControlStateNormal];
[button addTarget:self action:@selector(buttonTouched) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
UITextView* textView = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, 100, 40)];
[self.view addSubview:textView];
[textView becomeFirstResponder];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillHide:)
name:UIKeyboardWillHideNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:nil];
}
- (void)searchBarCancelButtonClicked:(UISearchBar *) searchBar{
[searchBar resignFirstResponder];
}
- (void) buttonTouched{
UIActionSheet* actionSheet = [[UIActionSheet …Run Code Online (Sandbox Code Playgroud) 当用户点击按钮时,我的应用程序中会显示一个带有UIAlertController的iOS应用程序.
这一切都很好,除了一件事,完成块不会因某种原因被调用.
这是我的代码:
// Setup the alert information/type.
UIAlertController *action_view = [UIAlertController alertControllerWithTitle:@"Test title" message:@"test message" preferredStyle:UIAlertControllerStyleActionSheet];
// Create and add the cancel button.
UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"Dismiss" style:UIAlertActionStyleCancel handler:^(UIAlertAction * action) {
[action_view dismissViewControllerAnimated:YES completion:^{
NSLog(@"asdhfgjk");
}];
}];
// Add the action button to the alert.
[action_view addAction:cancel];
// Present the alert to the user.
[self presentViewController:action_view animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)
如果您运行该代码,您将看到解除控制器不会运行的行,并且NSLog它内部的语句也不会.但是,如果你删除NSLog并将完成块设置为nil,那么它确实运行....为什么???
谢谢你的时间,丹.
我想实现UIAlertViewController这样的(参考:Pages和Keynote应用程序):
我已经实现了一个自定义的tableview,并通过模仿来呈现视图UIAlertViewController.但我无法实现与上面类似的用户界面.有没有可用的默认控制器?
-(void)share:(id)sender
{
[self setModalPresentationStyle:UIModalPresentationCurrentContext];
AlertViewController *renameCntrl = [self.storyboard instantiateViewControllerWithIdentifier:AlertTblViewidentifier];
renameCntrl.optionViewDelegate = self;
renameCntrl.providesPresentationContextTransitionStyle = YES;
renameCntrl.definesPresentationContext = YES;
[renameCntrl setModalPresentationStyle:UIModalPresentationOverCurrentContext];
[self presentViewController:renameCntrl animated:YES completion:nil];
}
Run Code Online (Sandbox Code Playgroud) 我想在iOS8上使用UIActionSheet,但它已被弃用,我不知道如何使用更新的方式来使用它...
看到旧代码:
-(void)acoesDoController:(UIViewController *)controller{
self.controller = controller;
UIActionSheet *opcoes = [[UIActionSheet alloc]initWithTitle:self.contato.nome delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Delete" otherButtonTitles:@"other", nil];
[opcoes showInView:controller.view];
}
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
//switch case of the buttons
}
Run Code Online (Sandbox Code Playgroud)
为了说清楚,在这个例子中,在UITableView索引中长按后激活了操作表.
如何以正确的方式实现上面的代码?
是否可以将取消按钮的颜色更改为红色,我知道我们可以使用破坏性样式
let cancelActionButton: UIAlertAction = UIAlertAction(title: "Cancel", style: .Destructive) { action -> Void in
print("Cancel")
}
Run Code Online (Sandbox Code Playgroud)
如果你在外面点击它,如何让你的uiactionsheet消失?这适用于iPhone.显然,ipad默认这样做(我可能错了).
我有一个UIActionSheet,我正在指定取消按钮但是当它点击时它不会被忽略?
UIActionSheet *actionSheet = [[[UIActionSheet alloc]initWithTitle:nil delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Target Complete" otherButtonTitles:nil] autorelease];
[actionSheet showInView:self.view];
Run Code Online (Sandbox Code Playgroud)
根据文档,我不需要任何代码,甚至当我尝试实现didCancel委托方法时,它从未调用过?
我正在将我的应用程序从目标c重写为Swift,我注意到UIActionSheet在Swift版本中的行为与在obj-c版本中的行为不同.
对象版本

Swift版本

这只是iOS 7上的一个问题,它在iOS 8上运行正常(意味着取消在底部),适用于Swift和Obj-c版本
这是相关的一段代码:
var sheet = UIActionSheet(title: nil, delegate: self, cancelButtonTitle: "Cancel", destructiveButtonTitle: nil)
sheet.addButtonWithTitle("Camera")
sheet.addButtonWithTitle("Photo Library")
sheet.showInView(self.controller.view)
Run Code Online (Sandbox Code Playgroud)
知道怎么解决吗?
uiactionsheet ×10
ios ×7
iphone ×4
objective-c ×4
swift ×2
cocoa-touch ×1
deprecated ×1
ios7 ×1
ios8 ×1
keyboard ×1
uitableview ×1