各セルにボタンが含まれているSwiftでテーブルビューを作成しています。 ボタンをタップすると、そのボタンにポップオーバーが表示されます。swift:テーブルビューのセル上のポップオーバーボタンは常に最初のセルに表示されます
私の問題は、どのセルをボタンをクリックしても、最初のセルに常にポップオーバーが表示されることです。
詳しくは添付の画像をご覧ください。以下は
tableviewcontrollerクラスで私のコードです。私はボタンをタッチすることを検出するためにタグを使用します。
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
// Table view cells are reused and should be dequeued using a cell identifier.
let cellIdentifier = "Cell01"
let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) as? UICell01
//when tap share button
cell!.shareButton.tag = indexPath.row
cell!.shareButton.addTarget(self, action: "shareAction:", forControlEvents: .TouchUpInside)
return cell!
}
@IBAction func shareAction(sender: UIButton) {
//Create Action Sheet to be menu
let alert:UIAlertController = UIAlertController(title: "Share on", message: nil, preferredStyle: UIAlertControllerStyle.ActionSheet)
let cancelAction = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel)
{
UIAlertAction in
}
// Add the actions
alert.addAction(cancelAction)
// Present the controller
if UIDevice.currentDevice().userInterfaceIdiom == .Phone
{
self.presentViewController(alert, animated: true, completion: nil)
}
else //iPad
{
var popover:UIPopoverController?=nil
popover = UIPopoverController(contentViewController: alert)
popover!.presentPopoverFromRect(sender.frame, inView: self.view, permittedArrowDirections: UIPopoverArrowDirection.Any, animated: true)
}
問題は最終行にあると思います。機能に渡される「送信者」は、最初のセルのボタンだけです。どのように問題を解決するのですか?