0

我有一个带有多个按钮的 alerviewcontroller。这些按钮是基于数组值创建的。我的代码如下所示,按钮操作无法正常工作。

 var alert : UIAlertController = UIAlertController(title: "Select student", message: nil , preferredStyle: UIAlertControllerStyle.Alert)

    for var j = 0; j < self.students.count; j++ {


        var student: UIAlertAction = UIAlertAction(title: self.students[j], style: UIAlertActionStyle.Default){

            UIAlertAction  in

            for var i = 0; i < self.students.count ; i++ {

                if alert.title == self.students[i]{
            dispatch_async(dispatch_get_main_queue(), {
                self.loader.startAnimating()
                println(i)
                self.studentLabel.text = self.students[i]
            })


            self.loadTimeTable(self.studentId[i])

                }

            }
        }

        alert.addAction(student)

    }
4

1 回答 1

1

你只是在创造它,alert而不是invoking它。在最后添加这一行

 self.presentViewController(alert, animated: true, completion: nil)
于 2015-08-06T06:44:17.563 回答