UIActionsheet不解雇

时间:2012-12-01 09:46:45

标签: iphone ios uiactionsheet

我的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];
}

但它并没有消失。我不想改变任何按钮的设计和位置。 我该怎么办?

5 个答案:

答案 0 :(得分: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
}

答案 1 :(得分:1)

从lpgr打开操作表时要小心。只能在“开始”时打开它,而不是在“结束”上打开它。

- (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
    }
}

答案 2 :(得分:0)

你必须将它添加到你的.h文件中。

 <UIActionSheetDelegate>

还要将此行添加到您的.m文件中。

 actionSheet.delegate = self;

让我知道,这是否有效。如果有效,请将其作为正确答案接受

答案 3 :(得分:-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
{
}

让我知道它是否有效

快乐编码!!!!!

答案 4 :(得分:-1)

这不是取消UIActionSheet的正确方法,首先您需要UIActionSheet禁用默认javascipt 并浏览此网页

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

相关问题