Chcę wykonać przejście z przycisku w niestandardowej UITableViewCell, ale nie wiem, jak uzyskać dostęp do zawartości komórki po naciśnięciu tego przycisku. Zdaję sobie sprawę, że można to osiągnąć poprzez didSelectRowAtIndexPath, jednak mam tę metodę wykonującą inną funkcję i chciałbym użyć przycisku, który utworzyłem w komórce tabeli.Wykonywanie przejścia z przycisku wewnątrz niestandardowego UITableViewCell
Tu jest moja metoda wykonywania segue Mam problem z:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?)
{
if segue.identifier == "showComments"
{
let vc:CommentOnPostViewController = segue.destinationViewController as CommentOnPostViewController
var buttonPosition:CGPoint = sender?.convertPoint(CGPointZero, toView: self.feed) as CGPoint!
var path:NSIndexPath = self.feed.indexPathForRowAtPoint(buttonPosition) as NSIndexPath!
var postToCommentOn:PFObject = feedList[path.row] as PFObject
vc.post = postToCommentOn as PFObject
}
}
otagować przycisk w komórce podczas wyświetlania go i dać mu działanie docelowa:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
// There is code that goes here for creating and displaying the cell.
cell.commentButton.tag = indexPath.row
cell.commentButton.addTarget(self, action: "addComment", forControlEvents: UIControlEvents.TouchUpInside)
}
Tutaj to czynność, która jest wywoływana po naciśnięciu przycisku:
func addComment()
{
self.performSegueWithIdentifier("showComments", sender: self)
}
Każda pomoc jest doceniana. Dzięki!
Może chcesz przekazać nie siebie, ale przycisk lub komórkę jako nadawcę? –
użyj delegata, aby osiągnąć coś takiego.Delegat zostanie zdefiniowany w klasie CustomCell, a na TableViewController ustawi delegata każdej komórki ... Na UITableViewController określ metodę delegata, która będzie Cię nazywała. performSegueWithIdentifier ... Z czystej ciekawości, co robisz z "didSelectRowAtIndexPath"? –