दस्तावेज़ कहता है कि विधि tableView:accessoryButtonTappedForRowWithIndexPath:
को कॉल नहीं किया जाता है जब indexPath
पर पंक्ति के लिए एक एक्सेसरी दृश्य सेट किया जाता है। विधि केवल तभी बुलाई जाती है जब accessoryView
संपत्ति शून्य होती है और जब कोई अंतर्निहित सहायक दृश्य प्रदर्शित करने के लिए accessoryType
प्रॉपर्टी का उपयोग करता है और सेट करता है। जैसा कि मैं इसे समझता हूं, accessoryView
और accessoryType
पारस्परिक रूप से अनन्य हैं। accessoryType
का उपयोग करते समय, सिस्टम tableView:accessoryButtonTappedForRowWithIndexPath:
को अपेक्षित के रूप में कॉल करेगा, लेकिन आपको स्वयं को अन्य मामले से संभालना होगा।
ऐप्पल ऐसा करता है जिस तरह से यह एसडीके की Accessory
नमूना परियोजना में दिखाया गया है। डेटासोर्स प्रतिनिधि के cellForRowAtIndexPath
विधि में, उन्होंने कस्टम एक्सेसरी बटन पर एक लक्ष्य/क्रिया निर्धारित की है। के बाद से एक कार्रवाई करने के लिए indexPath
पारित नहीं हो सकता है, वे इसी indexPath
को पुनः प्राप्त करने के लिए एक सहायक विधि कॉल और वे प्रतिनिधि विधि के लिए परिणाम पारित:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
...
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
...
// set the button's target to this table view controller so we can interpret touch events and map that to a NSIndexSet
[button addTarget:self action:@selector(checkButtonTapped:event:) forControlEvents:UIControlEventTouchUpInside];
...
cell.accessoryView = button;
return cell;
}
- (void)checkButtonTapped:(id)sender event:(id)event{
NSSet *touches = [event allTouches];
UITouch *touch = [touches anyObject];
CGPoint currentTouchPosition = [touch locationInView:self.tableView];
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint: currentTouchPosition];
if (indexPath != nil){
[self tableView: self.tableView accessoryButtonTappedForRowWithIndexPath: indexPath];
}
}
किसी कारण से, अपने सेटअप में गिर रहा है accessoryView केस। क्या आपने इंटरफ़ेस बिल्डर का उपयोग करने के बजाय कोड के साथ accessoryType सेट करने का प्रयास किया है?
क्या आप वाकई डेटा स्रोत और उचित वर्ग के लिए प्रतिनिधि जुड़े हैं? क्या '- (शून्य) तालिका दृश्य: (UITableView *) तालिका दृश्य देखा गया चयन करें IndexPath: (NSIndexPath *) indexPath' विधि कहलाती है? – Thermometer
हां (शून्य) तालिका दृश्य: (UITableView *) तालिका दृश्य देखा चयन करेंटएंड इंडेक्सपैथ: (एनएसआईएंडएक्सपाथ *) इंडेक्सपाथ बुलाया जा रहा है। – jimbob