UIActionSheet与swift [英] UIActionSheet with swift

查看:109
本文介绍了UIActionSheet与swift的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个操作表,但问题是没有调用委托方法

I created an action sheet, but the problem is that the delegate method is not called

 myActionSheet = UIActionSheet()
        myActionSheet.addButtonWithTitle("Add event")
        myActionSheet.addButtonWithTitle("close")
        myActionSheet.cancelButtonIndex = 1
        myActionSheet.showInView(self.view)

/// UIActionSheetDelegate

/// UIActionSheetDelegate

func actionSheet(myActionSheet: UIActionSheet!, clickedButtonAtIndex buttonIndex: Int){
        if(myActionSheet.tag == 1){

            if (buttonIndex == 0){
                println("the index is 0")
            }
        }
}

我使用了另一种适用于iOS 8的方法但不适用于iOS 7:

I used another way which worked good with iOS 8 but did not work with iOS 7:

var ActionSheet =  UIAlertController(title: "Add View", message: "", preferredStyle: UIAlertControllerStyle.ActionSheet)

ActionSheet.addAction(UIAlertAction(title: "Add event", style: UIAlertActionStyle.Default, handler:nil))

self.presentViewController(ActionSheet, animated: true, completion: nil)

有任何解决问题的想法吗?

Any idea to solve the problem?

推荐答案

您永远不会设置操作表的委托:

You never set the action sheet's delegate:

myActionSheet = UIActionSheet()
myActionSheet.delegate = self

这篇关于UIActionSheet与swift的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆