我在 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/