首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UIActionsheet未被忽略

UIActionsheet未被忽略
EN

Stack Overflow用户
提问于 2012-12-01 17:46:45
回答 5查看 2K关注 0票数 0

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

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

目前,他们中没有一个人为我做这项工作。

下面是我显示它的方式:

代码语言:javascript
复制
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];

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

代码语言:javascript
复制
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
      //some code
      [actionSheet dismissWithClickedButtonIndex:buttonIndex animated:YES];
}

但它不会对此置之不理。我不想改变我的设计和任何按钮的位置。我该怎么办?

EN

回答 5

Stack Overflow用户

发布于 2012-12-01 18:16:14

代码语言:javascript
复制
-(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
EN

Stack Overflow用户

发布于 2014-01-10 04:34:16

从lpgr打开动作单时要小心。只在“开始”时打开,不会在“结束”时再打开。

代码语言:javascript
复制
- (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
    }
}
票数 1
EN

Stack Overflow用户

发布于 2012-12-01 18:01:46

您必须将其添加到您的.h文件中。

代码语言:javascript
复制
 <UIActionSheetDelegate>

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

代码语言:javascript
复制
 actionSheet.delegate = self;

让我知道,这是工作或没有。如果有效,接受它作为正确的答案。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13658244

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档