2011-10-17 5 views
5

मैं निम्नलिखित सुझाव दिया दिनचर्या का इस्तेमाल किया है एक तालिका दृश्य कक्ष में विस्तार प्रकटीकरण बटन छवि बदलने के लिए (tableView cellForRowAtIndexPath में)एक विस्तार प्रकटीकरण बटन के लिए छवि में परिवर्तन करना (Xcode 4.2)

if (cell == nil) { 

    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil]; 

    UIButton *myAccessoryButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 24, 24)]; 
    [myAccessoryButton setBackgroundColor:[UIColor clearColor]]; 
    [myAccessoryButton setImage:[UIImage imageNamed:@"ball"] forState:UIControlStateNormal]; 
    [cell setAccessoryView:myAccessoryButton]; 
    cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton; 
} 

हालांकि, घटना tableView accessoryButtonTappedForRowWithIndexPath अब बटन पर क्लिक करने के लिए नहीं कहा जाता है।

क्या किसी के पास कोई विचार है?

उत्तर

5

मेरे पास मेरी परियोजना में एक ही समस्या है।

किसी को ऐसा करने का सही तरीका पता है?

Tnx

संपादित करें: इस post पर

देखो ... यह मेरे लिए काम नहीं है।

+1

+1 लेकिन एसओ – Rhubarb

6

मैंने फ्रा के जवाब को +1 किया है, लेकिन कोड को अन्य साइट से खींचने के लिए बस इतना अधिक पूरा करने के लिए: जवाब यह है कि आपको एक्सेसरीबूटन बटन को एक्सेस करना होगा .... कॉल स्वचालित रूप से नहीं बनाया जाएगा यह अंतर्निहित विस्तार-प्रकटीकरण के लिए होगा, इसलिए आपको इसे बटन के लक्ष्य के साथ स्वयं करना होगा।

ऊपर अपना उदाहरण के लिए लिंक कोड से अनुवाद कर रहा है, setImage के बाद इस पंक्ति जोड़ें:

[myAccessoryButton addTarget:self action:@selector(accessoryButtonTapped:event:) forControlEvents:UIControlEventTouchUpInside]; 

फिर इस पर बाद में जोड़ें:

- (void)accessoryButtonTapped:(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]; 
    } 
} 

(this link से शब्दशः नकल की)

ध्यान दें कि यह मानता है कि बटन UITableViewController में बनाया गया है (मेरे मामले में मैं एक कस्टम सेल में एक बना रहा हूं, इसलिए संदर्भ थोड़ा भिन्न हैं एनटी)

स्पष्टीकरण: accessoryButtonTapped हमारे कस्टम बटन के लिए एक कस्टम लक्ष्य विधि है। जब बटन दबाया जाता है ("TouchUpInside") तो उस बिंदु पर सेल के इंडेक्सपैथ को उस बिंदु पर मिलता है जिसमें प्रेस हुआ था, और जिस विधि को तालिका दृश्य सामान्य रूप से लागू किया जाएगा उस विधि का आह्वान करें।

+0

ग्रेट छोड़ने से बचने के लिए नीचे दिए गए एक अलग उत्तर में विवरण में खींच लिया गया ... एक समान कार्यान्वयन यहां है: http://iosdevblog.com/2014/07/26/custom-image- के लिए-विस्तार प्रकटीकरण बटन / – plusangel

संबंधित मुद्दे