我在 StackOverflow 上从另一个用户那里找到了这个,你可能会发现它很有用,就像我一样
将 UIView 添加为 UIActionSheet 上的子视图
祝你好运,如果您找到任何其他解决方案,请告诉我们:)
更新:我会远离 UIACtionSheet,因为它在 iOS 8 以后已被弃用。您现在需要使用 UIAlertController。我会使用这样的东西:
UIAlertController * alert=[UIAlertController alertControllerWithTitle:@"Connection Method"
message:@"Select Connection Method"
preferredStyle:UIAlertControllerStyleActionSheet];
//These will essentially be the buttons that we used to create for UIActionSheet. They are created pretty much the same way as how they used to,
//but you have to declare their corresponding action here too.
UIAlertAction* firstAction = [UIAlertAction actionWithTitle:@"Title1"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
declaredVariable = NO;
[alert dismissViewControllerAnimated:NO completion:nil];
[self doSomethingHereOrExecuteTheFunctionYouNeed];
}];
UIAlertAction* secondAction = [UIAlertAction actionWithTitle:@"Title2 and so on"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
BOOL newVarable = YES;
[alert dismissViewControllerAnimated:NO completion:nil];
[self followAlertControllerChoice];
}];
UIAlertAction* cancel = [UIAlertAction actionWithTitle:@"Cancel button"
style:UIAlertActionStyleCancel
handler:^(UIAlertAction * action) {
[alert dismissViewControllerAnimated:YES completion:nil];
}];
//Add buttons ("Actions") here
[alert addAction:firstAction];
[alert addAction:secondAction];
[alert addAction:cancel];
//Finally, present your alertcontroller
[self presentViewController:alert animated:YES completion:nil];
AFAIK,您只能将文本字段添加到警报控制器,您可以这样做:
[alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.placeholder = @"Enter your text here";
textField.textAlignment = NSTextAlignmentLeft;
//如此等等 }];
显然,Apple 不希望我们将 UIAlertController 子类化,如下所示:
UIAlertController 类旨在按原样使用,不支持子类化。此类的视图层次结构是私有的,不得修改。