iPhone:处理多个操作表

发布于 2024-09-13 20:03:31 字数 273 浏览 7 评论 0原文

我的视图之一使用了 3 个操作表,这些操作表是在单击各个按钮时生成的。由于我只有一个 - (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex 方法,那么了解我正在处理哪个操作表的最佳方法是什么?选择任何一个actionSheets 上的第一个按钮都是buttonIndex 0。所以我需要知道如何知道来自哪个actionSheet 调用。

有想法吗?

One of my views uses 3 action sheets that come from when various buttons are clicked. Since I only have one - (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex method, what is the best way to know which action sheet I am dealing with? Choosing the first button on any of my actionSheets would be buttonIndex 0. So I need to know how to know which actionSheet call that is coming from.

Ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

予囚 2024-09-20 20:03:31

您需要在创建操作表时设置标签并在操作表方法中对其进行测试。

You need to set the tag when you create the action sheet and test against that in your action sheet method.

晨光如昨 2024-09-20 20:03:31

我遇到了同样的问题,我只是根据操作表的标题设置了一个条件:

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


if (actionSheet.title == @"present action sheet A") {

//do some stuff

}
if (actionSheet.title == @"present action sheet B") {

//do some stuff

}

Works like a charm,不确定操作表是否有标签,但也许我错了。

I had the same issue and I simply set up a conditional based on the action sheet's title:

in

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


if (actionSheet.title == @"present action sheet A") {

//do some stuff

}
if (actionSheet.title == @"present action sheet B") {

//do some stuff

}

Works like a charm, not sure if action sheets have tags, maybe im wrong though.

轻许诺言 2024-09-20 20:03:31

对 3 个操作表使用类级别变量。然后你可以在actionSheet方法中比较action的来源。

Use class level variable for 3 actionsheet. Then you can compare the source of action in the actionSheet method.

饭团 2024-09-20 20:03:31

创建操作时设置标签

UIActionSheet * actionSheet = 
[[UIActionSheet alloc] 
initWithTitle:@"My title" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil  otherButtonTitles:@"Option1",@"Option2", nil];

actionSheet.tag = 1100;





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

{

if(actionSheet.tag == 1100)
{

    switch (buttonIndex) 
    {
        case 0: 
        {  
        }
           break;
        case 1:
        {

        }
            break;
        default:
            break;
    }  
}  
}

Set the Tag when you create an action

UIActionSheet * actionSheet = 
[[UIActionSheet alloc] 
initWithTitle:@"My title" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil  otherButtonTitles:@"Option1",@"Option2", nil];

actionSheet.tag = 1100;





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

{

if(actionSheet.tag == 1100)
{

    switch (buttonIndex) 
    {
        case 0: 
        {  
        }
           break;
        case 1:
        {

        }
            break;
        default:
            break;
    }  
}  
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文