हाइलाइटव्यू हाइलाइटिंग को अक्षम करें लेकिन व्यक्तिगत कोशिकाओं के चयन की अनुमति दें


83

जब आप किसी सेल पर टैप करते हैं तो पंक्ति चयनित हो जाती है और हाइलाइट हो जाती है। अब मैं क्या करना चाहता हूं, हाइलाइटिंग को अक्षम करना है, लेकिन चयन की अनुमति दें। इसके आसपास एक तरीका है। यह सवाल है जो इसका उत्तर देता है, लेकिन यह चयन और हाइलाइटिंग दोनों को अक्षम करता है।


8
cell.selectionStyle = UITableViewCellSelectionStyleNone;इसे अपनी cellForRowAtIndexPathविधि में जोड़ें
श्रुति

जवाबों:


182

आप स्टोरीबोर्ड से सेल की चयन शैली को "कोई नहीं" पर सेट कर सकते हैं:

यहाँ देखें

या कोड से:

cell.selectionStyle = UITableViewCellSelectionStyleNone;

स्विफ्ट 3 के लिए:

cell.selectionStyle = UITableViewCellSelectionStyle.none

स्विफ्ट 4 और इसके बाद के संस्करण के लिए:

cell.selectionStyle = .none

जब मैं "कोई नहीं" का चयन करता हूं तो मैं हाइलाइट किए गए राज्य के काम करने की क्षमता खो देता हूं। क्या मैं उस राज्य को खोए बिना किसी को भी / सफेद पृष्ठभूमि नहीं बना सकता हूं?
शॉन

यह किस समारोह में जाएगा? मैं "cellForRowAt" अनुमान लगा रहा हूँ?
डैनियल स्प्रिंगर

आपको इसे सेल में करना चाहिए न कि
टेबलव्यू

26

बदलें UITableViewCellके selectedBackgroundViewपारदर्शी करने के लिए रंग।

    let clearView = UIView()
    clearView.backgroundColor = UIColor.clearColor() // Whatever color you like
    UITableViewCell.appearance().selectedBackgroundView = clearView

या एक विशिष्ट सेल के लिए सेट करने के लिए:

cell.backgroundView = clearView


1
यह सबसे अच्छा विकल्प है, क्योंकि cell.selectionStyle = UITableViewCellSelectionStyleNoneकभी-कभी ऐपल्स एनीमेशन लॉजिक के अंदर कुछ गहराई से टूट जाता है।
orkenstein

इसके बजाय प्रयोग करें ..UITableViewCell.appearance().selectionStyle = .None
वैभव

यह उपयोग करने के लिए अच्छा है यदि आपके पास सेल के भीतर चयन करने योग्य चीजें हैं।
मैथ्यू कोरपोराल

उत्कृष्ट समाधान। इस कोड को सेल के awakeFromNib()फंक्शन में
रखना

यह विकल्प टेबल व्यू सेल सेपरेटर लाइन को नहीं देखा जाता है।
jonye ._। Jin

8

सेल चयन शैली को किसी पर सेट करने का प्रयास करें -

[cell setSelectionStyle:UITableViewCellSelectionStyleNone];

इससे आपकी समस्या दूर हो जाएगी



6

स्विफ्ट के लिए:

UITableViewCell.selectionStyle = UITableViewCellSelectionStyle.None;

या जब आप किसी सेल को स्विफ्ट में उपवर्गित करते हैं:

class CustomCell : UITableViewCell {

    required init(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)!
        selectionStyle = .None
    }

}


2

कस्टम रंग जोड़ने के लिए नीचे दिए गए कोड का उपयोग करें। और इसे पारदर्शी उपयोग करने के लिएalpha: 0.0

cell.selectedBackgroundView = UIView(frame: CGRect.zero)
cell.selectedBackgroundView?.backgroundColor = UIColor(red:0.27, green:0.71, blue:0.73, alpha:1.0)

यदि आप कस्टम रंग का उपयोग करते हैं और इसे गोल कोने का उपयोग देना चाहते हैं:

cell.layer.cornerRadius = 8

इसके अलावा, बेहतर एनीमेशन और फील के लिए इसका इस्तेमाल करें

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

    tableView.deselectRow(at: indexPath, animated: true)
}

1

स्विफ्ट 3 में प्रोग्रामेटिक तरीके की तलाश करने वालों के लिए

cell.selectionStyle = UITableViewCellSelectionStyle.none


1

आप सेल की चयन संपत्ति को स्टोरीबोर्ड में ही सेट कर सकते हैं यहां छवि विवरण दर्ज करें


0

Objc के लिए:

[सेल सेटइसेलेक्शन सेलेक्ट: यूआईटेबल व्यूसेलसेलीनेशन सेलेनी];

- (void)viewDidLoad {
  [super viewDidLoad];
  _tableView.allowsSelection = YES;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    .. .. .. .. 
   [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
   . . . . .. 
}

0

के लिए स्विफ्ट 5 सबसे अच्छा तरीका है:

cell.selectionStyle = .none

-1

यहां स्विफ्ट 3 के लिए समाधान है, संपादन मोड में भी काम करता है

cell.selectionStyle = .gray
cell.selectedBackgroundView = {

    let colorView = UIView()
    colorView.backgroundColor = UIColor.black.withAlphaComponent(0.0)
    //change the alpha value or color to match with you UI/UX

    return colorView
}()
हमारी साइट का प्रयोग करके, आप स्वीकार करते हैं कि आपने हमारी Cookie Policy और निजता नीति को पढ़ और समझा लिया है।
Licensed under cc by-sa 3.0 with attribution required.