【发布时间】:2016-08-09 09:33:43
【问题描述】:
我想在 iPhone 和 iPad 设备上都显示ActionSheet。虽然我的代码在 iPhone 上正常工作,但在 iPad 上却不行。这样做的原因是我需要指定显示弹出框的位置。因此,我尝试使用this answer 中提出的代码。我目前遇到的问题是,我不知道如何将参数 sender 传递给方法。
例如,我有一个UITableViewRowAction,单击它时应显示ActionSheet:
func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? {
let rowAction = UITableViewRowAction(style: UITableViewRowActionStyle.Default, title: "Action", handler:{action, indexpath in
print("Action for element #\(indexPath.row).");
self.displayActionSheet()
});
return [rowAction];
}
在我的情况下,sender 是哪个参数?我无法将rowAction 传递给displayActionSheet(),因为该变量是在其自己的初始值中使用的。我也尝试传递self.displayDeleteLicencePlateActionSheet(self.items[indexPath.row]),但结果相同——我总是在guard 表达式的else 子句中结束:
guard let button = sender as? UIView else {
print("sender empty")
return
}
我还想在点击UIBarButtonItem 时显示ActionSheet:
let myButton = UIBarButtonItem(title: "FooBar", style: .Plain, target: self, action: #selector(SecondViewController.displaySecondActionSheet(_:)))
但结果相同。如何做到这一点?
【问题讨论】:
标签: ios swift ipad uialertview uiactionsheet