मेरे पास UITableViewCell
के साथ एक साधारण समस्या है। मैं जो चाहता हूं वह किसी चयनित सेल के टेक्स्ट रंग को बदलना है। मेरी cellForRowAtIndexPath
विधि में, मैं सेट:UITableView सेल टेक्स्ट लेबल रंग
cell.textLabel.textColor = [UIColor whiteColor];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.textLabel.highlightedTextColor = [UIColor orangeColor];
तो selectionStyle
UITableViewCellSelectionStyleNone
है, highlightedTextColor
नहीं बदलेगा। तो मैं इन दोनों तरीकों का उपयोग पाठ रंग सेट करने के लिए:
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView cellForRowAtIndexPath:indexPath].textLabel.textColor = [UIColor orangeColor];
return indexPath;
}
- (NSIndexPath *)tableView:(UITableView *)tableView willDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView cellForRowAtIndexPath:indexPath].textLabel.textColor = [UIColor whiteColor];
return indexPath;
}
यह काम करता है, लेकिन tableview स्क्रॉल जब, रंग वापस बदल जाता है।
एनएसआईएनएक्सएक्सपीथ * urIndexPath घोषित करने के बारे में क्या; आपके। एच में फिर आपके didSelecteRowAtIndexPath विधि में, चयनित सेल के इंडेक्सपैथ को urIndexPath पर पास करें, फिर UI को अपडेट करने के लिए डेटा को पुनः लोड करें, अपने सेलफॉररएट इंडेक्सपैथ में, कुछ ऐसा कहें, अगर urIndexPath == indexPath {नारंगी रंग सेट करें; } else {डिफ़ॉल्ट रूप से जो भी रंग डिफ़ॉल्ट है} – janusbalatbat
@Akhildas जब आप तालिका को स्क्रॉल करते हैं, तो सेलफोररोएटइंडेक्स देखें: विधि हमेशा कॉल की जाएगी। लेकिन आपके पास अन्य विधियां नहीं हैं। बेहतर है कि आप इसे "सेलफोररोएट इंडेक्स:" विधि के अंदर "WillSelectRowAtIndexPath" विधि को कॉल कर सकते हैं काम करता है –