iOS-8 and later - UITableView inside an UIAlertController

前端 未结 4 2059
一向
一向 2020-12-09 13:57

I know how to add any Custom UI inside UIAlertView by using accessoryView like UITableView but I am now curious that if w

4条回答
  •  再見小時候
    2020-12-09 14:27

    Here's @Syed Ali Salman's answer in simplified form in Swift:

    let alertController = UIAlertController(title: "The Title",
                                            message: "Here's a message.",
                                            preferredStyle: .Alert)
    
    let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel)
    { (action) in
        // ...
    }
    alertController.addAction(cancelAction)
    
    let okAction = UIAlertAction(title: "OK", style: .Default)
    { (action) in
        // ...
    }
    alertController.addAction(okAction)
    
    let tableViewController = UITableViewController()
    tableViewController.preferredContentSize = CGSize(width: 272, height: 176) // 4 default cell heights.
    alertController.setValue(tableViewController, forKey: "contentViewController")
    
    yourTopViewController().presentViewController(alertController, animated: true)
    {
        // ...
    }
    

提交回复
热议问题