ios - 如何使用 actionsheet showInView 方法,以便它可以在我的 VC 和 UIView 中显示

标签 ios objective-c uiview uiviewcontroller

我在 UIView 中创建了一个名为 ellipses 的方法,此方法正在创建一个 Action 表。我试图在我的 UIViewController 中调用此方法,但由于“[actionSheet showInView:self]”而失败。由于“自我”,此 Action 表在我的 View 中工作正常' 但我不知道如何修复“自我”,以便它可以在我的 VC 和我的 View 中显示。

这是我在 UIView 中的代码的一部分

- (void)ellipses{

NSString *deleteButtonName = NSLocalizedString(@"Delete", @"");
NSString *copyButtonName = NSLocalizedString(@"Copy to clipboard", @"");
NSString *cancel = NSLocalizedString(@"Cancel", @"");

NSArray *buttons;


buttons = [NSArray arrayWithObjects:deleteButtonName, copyButtonName, nil];


UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil
                                                         delegate:self
                                                cancelButtonTitle:nil
                                           destructiveButtonTitle:nil
                                                otherButtonTitles:nil];

for(NSString *title in buttons)  {
    [actionSheet addButtonWithTitle:title];
}

[actionSheet addButtonWithTitle:cancel];
[actionSheet setCancelButtonIndex:[buttons count]];
[actionSheet showInView:self]; // here is gonna be a problem later
}

这是我的 UIViewController 中的部分代码
-(void)loadView{
    newView *nView = [newView new];
    [self setView:nView];
    UIButton *testButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [testButton setTitle:@"Test" forState:UIControlStateNormal];
    [testButton setFrame:CGRectMake(200, 230, 60, 28)];
    [testButton setUserInteractionEnabled:YES];
    [testButton addTarget:self action:@selector(actionSh) forControlEvents:UIControlEventTouchUpInside];
    [nView addSubview:testButton];
}

-(void)actionSh{
newView *newview = [[newView alloc] init];
[newview ellipses];//CALL ellipses
[newview setNeedsDisplay];
}

最佳答案

我的问题的答案:
在我的 VC.newView 中添加这个方法就是我的 UIView。

- (newView *) newview {

return (newView *)[self view];

}

并从我的 VC 调用方法
-(void)actionSH {
[[self newview] ellipses];
} 

关于ios - 如何使用 actionsheet showInView 方法,以便它可以在我的 VC 和 UIView 中显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24461033/

相关文章:

iphone - MFMessageComposeViewController:如何限制以蜂窝消息而不是 iMessage 的形式发送消息

ios - 如何在 UIScrollView 中临时隐藏非事件页面

ios - 意外的 CFBundleExecutable key 。 Aviary SDK Resources.bundle 中的包

iphone - 按字符串值对字符串的 NSMutableArray 进行排序

ios - 为什么使用 __block 标识符设置属性时应用程序会崩溃

ios - 是否可以使UIView闪屏

ios - 向使用 SnapKit 定位的 UIView 添加阴影

iphone - UIView子类默认属性

ios - Swift 4 - 随机顺序的多个表格 View 单元格类型

ios - 触发 segue 时出现错误 "fatal error: unexpectedly found nil while unwrapping an Optional value"