2013-08-02 8 views
9

बदल सकते हैं नहीं मैं सेट:UITableView नीले हाइलाइट रंग

cell.selectionStyle = UITableViewCellSelectionStyleGray; 

और एक पंक्ति हाइलाइट करने के कोड का उपयोग करें:

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection: 0]; 
[self.tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone 

हाइलाइट रंग हमेशा नीले भी मैं ग्रे निर्धारित किया है। यदि मैं सेट करता हूं:

cell.selectionStyle = UITableViewCellSelectionStyleNone; 

यह ठीक काम करता है और कोई हाइलाइट नहीं करता है। लेकिन बस इसके साथ काम न करें:

cell.selectionStyle = UITableViewCellSelectionStyleGray; 

यह सिर्फ भूरे रंग के बजाय नीले रंग का रंग दिखाता है। कोई उपाय? धन्यवाद।

+0

कृपया कोड है कि के लिए पूर्ण विधि निकायों शामिल पोस्ट के लिए स्वतंत्र महसूस हो, तो जहां आप चयन रंग सेट कर रहे हैं और चयन कर रहे हैं। –

+0

आप आईओएस 7 में इसे आजमाने की संभावना से नहीं हैं, है ना? –

उत्तर

28

इस प्रकार के रूप में यह लागू: -

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *) indexPath { 

    [cell setSelectionStyle:UITableViewCellSelectionStyleGray];  
} 

या

सेट selectedBackgroundView की आप अपने कस्टम tableview कक्ष में क्या चाहते हैं (जो UITableViewCell का एक उपवर्ग है) के रूप में रंग:

UIView * selectedBackgroundView = [[UIView alloc] initWithFrame:self.frame]; 
[selectedBackgroundView setBackgroundColor:[UIColor redColor]]; // set color here 
[self setSelectedBackgroundView:selectedBackgroundView]; 

या आप इसे -tableView:cellForRowAtIndexPath: विधि में कॉन्फ़िगर कर सकते हैं:

//... 
[cell setSelectedBackgroundView:selectedBackgroundView]; 
//... 
+0

धन्यवाद। इसने काम कर दिया। मैं एक कस्टम सेल का उपयोग करें। SetSelectionStyle की तरह दिखें: UITableViewCellSelectionStyleGray कस्टम सेल के साथ काम नहीं करता है। – user2543991

+6

इसके अलावा, आपको फ्रेम सेट करने की आवश्यकता नहीं है, इसलिए चयन रंग सेट करने का सबसे छोटा तरीका इन तालिकाओं में 'tableView: cellForRowAtIndexPath: ': ' cell.selectedBackgroundView = [[UIView alloc] init]; cell.selectedBackgroundView.backgroundColor = [UIColor redcolor]; ' (अगर आप एआरसी का उपयोग नहीं कर रहे हैं तो init में एक ऑटोरेलीज जोड़ें।) –

0

इंटरफ़ेसबिल्डर में या cellForRowAtIndexPath: विधि में इस प्रकार की कॉन्फ़िगरेशन करना सुनिश्चित करें।

+0

हां। मैंने पहली बार आईबी में किया और काम नहीं किया। फिर, मैंने cellForRowAtIndexPath में किया और अभी भी काम नहीं किया। – user2543991

0

यह सुनिश्चित करने के लिए कि आपने टाइपो नहीं बनाया है, "UITableViewCellSelectionStyleBlue" की वैश्विक खोज बनाएं।

14

ध्यान दें कि iOS 7,

का उपयोग करने में

[सेल setSelectionStyle: UITableViewCellSelectionStyleBlue];

अपेक्षित काम नहीं करेगा, क्योंकि आईओएस 7 में यह अब ग्रे है, भले ही आप ऊपर निरंतर पास करते हैं। देखें:

https://developer.apple.com/library/ios/documentation/uikit/reference/UITableViewCell_Class/Reference/Reference.html#//apple_ref/c/tdef/UITableViewCellSelectionStyle

4

बस के लिए अपने काम अपने विधि में इस ऐड मुझे

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
.... 
UIView *bgColorView = [[UIView alloc] init]; 
bgColorView.backgroundColor = [UIColor colorWithRed:(76.0/255.0) green:(161.0/255.0) blue:(255.0/255.0) alpha:1.0]; // perfect color suggested by @mohamadHafez 
bgColorView.layer.masksToBounds = YES; 
cell.selectedBackgroundView = bgColorView; 
.... 
return cell; 
} 

आप किसी भी सवाल पूछने के लिए

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