के भीतर किसी बटन से एक सेग्यू निष्पादित करना मैं कस्टम UITableViewCell के भीतर एक बटन से एक सेग्यू करना चाहता हूं, लेकिन मुझे नहीं पता कि जब मैं उस बटन को दबाता हूं तो सेल की सामग्री तक कैसे पहुंचना है। मुझे एहसास है कि यह didSelectRowAtIndexPath के माध्यम से पूरा किया जा सकता है, हालांकि मेरे पास यह तरीका एक और फ़ंक्शन कर रहा है, और मैं टेबल सेल के अंदर बनाए गए बटन का उपयोग करना चाहता हूं।एक कस्टम UITableViewCell
यहाँ मेरी प्रदर्शन segue विधि मैं कुछ समस्या आ रही है:
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
}
}
जब यह प्रदर्शित मैं कक्ष में बटन को टैग, और यह एक लक्ष्य कार्रवाई दे:
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)
}
यहाँ वह बटन है जिसे बटन दबाते समय कहा जाता है:
func addComment()
{
self.performSegueWithIdentifier("showComments", sender: self)
}
किसी भी मदद की सराहना की जाती है। धन्यवाद!
क्या आप स्वयं को नहीं भेज सकते हैं, लेकिन बटन या सेल प्रेषक के रूप में? –
इस तरह कुछ करने के लिए एक प्रतिनिधि का उपयोग करें।प्रतिनिधि को कस्टमसेल क्लास पर और टेबलव्यू कंट्रोलर पर परिभाषित किया जाएगा प्रत्येक सेल के प्रतिनिधि को सेट करें ... UITableViewController पर प्रतिनिधि के तरीके को परिभाषित करें जो आपको स्वयं कॉल करेगा। performSegueWithIdentifier ... जिज्ञासा से बाहर क्या आप "didSelectRowAtIndexPath" के साथ क्या कर रहे हैं? –