0

我的 UIActionsheet 中有 3 个按钮。我想在它的底部有一个取消按钮。

我还希望所有按钮都应该能够关闭 UIActionsheet。

目前,他们都没有为我做这项工作。

这是我的显示方式:

UIActionSheet *actionSheet = nil;
NSArray *otherButtons = nil;


otherButtons = [NSArray arrayWithObjects:@"Button1", @"Button2", @"Button3",
                     nil];       

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


for( NSString *btntitle in otherButtons)
{
    [actionSheet addButtonWithTitle:btntitle];
}    

[actionSheet addButtonWithTitle:@"Cancel"];
actionSheet.cancelButtonIndex = actionSheet.numberOfButtons - 1;

actionSheet.actionSheetStyle = UIActionSheetStyleDefault;
[actionSheet showInView:self.view];

在我的代表中,我这样做:

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
      //some code
      [actionSheet dismissWithClickedButtonIndex:buttonIndex animated:YES];
}

但它并没有解雇。我不想更改任何按钮的设计和位置。我应该怎么办?

4

5 回答 5

1

Be careful when opening an action sheet from a lpgr. Only open it on "Began", not again on "Ended".

- (void) handleLongPress:(UILongPressGestureRecognizer *)gestureRecognizer
{
    CGPoint p = [gestureRecognizer locationInView:self.tblYourVids];

    if (gestureRecognizer.state == UIGestureRecognizerStateBegan) {
        NSIndexPath *indexPath = [self.aTable indexPathForRowAtPoint:p];
        if (indexPath == nil)
            NSLog(@"long press on table view but not on a row");
        else {
            NSLog(@"long press on table view at row %d", indexPath.row);
            self.selectedCell = [self.aTable cellForRowAtIndexPath:indexPath];
            DLog(@"open action sheet only once");
            [self showActionSheet];
        }
    } else if (gestureRecognizer.state == UIGestureRecognizerStateEnded) {
        // eat this one
    }
}
于 2014-01-09T20:34:15.727 回答
1
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{

    [actionSheet dismissWithClickedButtonIndex:buttonIndex animated:YES];
    [self performSelector:@selector(OtherOperations) withObject:nil afterDelay:0.0];

}

-(void)OtherOperations{      //some code
}
于 2012-12-01T10:16:14.423 回答
0

you have to add this to yours .h file.

 <UIActionSheetDelegate>

Also add this line to yours .m file.

 actionSheet.delegate = self;

Let me know, this is working or not. If works, accept it as right answer

于 2012-12-01T10:01:45.853 回答
-1

这不是取消的正确方法,UIActionSheet首先您必须禁用默认设置并UIActionSheet通过javascipt 此网络

http://www.icab.de/blog/2010/07/11/customize-the-contextual-menu-of-uiwebview/

于 2012-12-01T10:32:21.853 回答
-1

只需尝试使用以下代码。它会自动关闭。

UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@""
                                                       delegate:self
                                              cancelButtonTitle:@"cancel"
                                         destructiveButtonTitle:@"Printer"
                                              otherButtonTitles: nil];

    [sheet showInView:self.view];
    [sheet release];


-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
}

让我知道它是否有效

快乐编码!!!!

于 2012-12-01T10:10:01.673 回答