我在UIView中创建了一个名为省略的方法,这个方法正在创建一个动作表。我试图在我的UIViewController中调用这个方法但由于“[actionSheet showInView:self]”而失败。这个动作表在我的视图中工作正常,因为'自我',但我不知道如何修复'自我',以便它可以在我的VC和我的视图中显示。
这是我在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];
}
答案 0 :(得分:0)
我的问题的答案: 在我的VC.newView中添加此方法是我的UIView。
- (newView *) newview {
return (newView *)[self view];
}
并从我的VC调用方法
-(void)actionSH {
[[self newview] ellipses];
}