2013-03-29 6 views
8

मैं स्टोरीबोर्ड का उपयोग करके एक स्थिर सेल को एक क्रिया के साथ कनेक्ट करना चाहता हूं। समस्या यह है कि आप सेल को एक क्रिया से कनेक्ट नहीं कर सकते हैं इसलिए मैंने इसे एक और तरीके से आजमाया।एक क्रिया के साथ स्थिर सेल कनेक्ट करें

@property (nonatomic, strong) IBOutlet UITableViewCell *theStaticCell; 

और

UITableViewCell *theCellClicked = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:1]]; 
if (theCellClicked == _theStaticCell) { 
    NSLog(@"Static cell clicked"); 
} 

तो मैं "अपडेट" सेल का उपयोग करना चाहते हैं, आप इसे क्लिक करते हैं कि: तो मेरी हेडर फाइल में मैं स्थिर सेल स्टोरीबोर्ड का उपयोग कर के साथ इस संपत्ति कनेक्ट किए गए उपरोक्त कोड निष्पादित हो जाता है।

enter image description here

उत्तर

14
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if (indexPath.section ==1 && indexPath.row == 0) 
    { 
     //Do what you want to do. 
    } 
} 

या

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    // Cell will be deselected by following line. 
    [self.tableView deselectRowAtIndexPath:indexPath animated:YES]; 

    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; 
    UITableViewCell *staticCell = [tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:1]]; 

    if (cell == staticCell) 
    { 
     //Do what you want to do. 
    } 
} 
+0

समस्या तब होती है जब मैं सेल पर क्लिक करता हूं, उस सेल की पृष्ठभूमि नीली हो जाती है और यह गायब नहीं होती है, मैं इसे गायब होने कैसे दे सकता हूं? –

+1

@nonuma संपादित उत्तर देखें। – viral

+0

अगर मैं स्टोरीबोर्ड का उपयोग कर रहा हूं तो मुझे यह कैसे करना चाहिए? –

3

मैं स्थिर सेल के साथ जोड़ने के बजाय लगता है कि आप का उपयोग करना चाहिए tableview प्रतिनिधि विधि

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
// Put your action logic here by using its index "indexPath.row". 
} 
1
#pragma mark - Table view delegate 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if([tableView cellForRowAtIndexPath:indexPath] == self.theStaticCell){ 
     NSLog(@"Static cell clicked"); 
    } 
} 
संबंधित मुद्दे