ios - UITableViewCell subclass's content duplicated -


मुझे इस कोड के साथ UItableViewCell subclass मिल गया है:

 < कोड> #import "RegisterTableViewCell.h" @ कार्यान्वयन रजिस्टरटैब दृश्यकेल - (आईडी) initWithStyle: (UITableViewCellStyle) शैली reuseIdentifier: (NSString *) reuseIdentifier {आत्म = [सुपर initWithStyle: शैली reuseIdentifier: reuseIdentifier]; यदि (स्वयं) {// प्रारंभ कोड _ टीटीओलो = [[यूआईएलबल एलोक] इनिटविथफ्रेम: सीजीआरएक्टमेक (10, 0, 80, सेल्फफ़्रेमआकार। हाइट)]; _titolo.numberOfLines = 0; _titolo.lineBreakMode = NSLineBreakByWordWrapping; [Self.contentView addSubview: _titoll]; _लाइनरेक्टांगोलरे = [[UIView alloc] initWithFrame: CGRectMake (100, 10, 1, 25)]; _linearettangolare.backgroundColor = [UIColor सफेद रंग]; [self.contentView addSubview: _linearettangolare]; _input = [[UITextField alloc] initWithFrame: CGRectMake (_linearettangolare.frame.origin.x + 6, 10, स्व.फ्रेम.size.width-110, 25)]; [Self.contentView addSubview: _input]; } स्वस्थ वापसी; } - (शून्य) awakeFromNib {// प्रारंभिक कोड} - (शून्य) सेटसेटेड: (BOOL) चयनित एनिमेटेड: (BOOL) एनिमेटेड ([सुपर सेट चयनित: चयनित एनिमेटेड: एनिमेटेड]; // चयनित राज्य के लिए दृश्य कॉन्फ़िगर करें} @end   

और एक सेलफ़ोराइट इंडीथ इस तरह लिखा विधि:

  - ( UITableViewCell *) तालिकादृश्य: (UITableView *) तालिका दृश्य सेलफोराअटइंडपैथ: (NSIndexPath *) सूचकांकपथ {स्थिर NSString * cellIdentifier = @ "सेल"; RegisterTableViewCell * सेल = [tableView dequeueReusableCellWithIdentifier: cellIdentifier]; यदि (सेल == नीला) {सेल = [[रजिस्टरटेबलव्यूससेल आलोक] initWithStyle: UITableViewCellStyleDefault reuseIdentifier: cellIdentifier]; } Cell.titolo.text = @ "कंफ़र्म पासवर्ड:"; cell.titolo.font = [UIFont boldSystemFontOfSize: 13]; यदि (indexPath.row% 2 == 0) {सेल। बैकग्राउंड कल्वर = [UIColor colorWithRed: 143 / 255.0 हरा: 177 / 255.0 नीला: 188 / 255.0 अल्फा: 1.0 / 1.0]; cell.titolo.textColor = [UIColor whiteColor]; cell.linearettangolare.backgroundColor = [UIColor whiteColor]; cell.input.textColor = [UIColor whiteColor]; Cell.input.secureTextEntry = FALSE; } Else {cell.backgroundColor = [UIColor colorWithRed: 175 / 255.0 हरा: 20 9 / 255.0 नीला: 227 / 255.0 अल्फा: 1.0 / 1.0]; Cell.titolo.textColor = [UIColor colorWithRed: 138 / 255.0 हरा: 140 / 255.0 नीला: 142 / 255.0 अल्फा: 1.0 / 1.0]; Cell.linearettangolare.backgroundColor = [UIColor colorWithRed: 138 / 255.0 हरा: 140 / 255.0 नीला: 142 / 255.0 अल्फा: 1.0 / 1.0]; Cell.input.textColor = [UIColor colorWithRed: 138 / 255.0 हरा: 140 / 255.0 नीला: 142 / 255.0 अल्फा: 1.0 / 1.0]; Cell.input.secureTextEntry = TRUE; } रिटर्न सेल; }   

मुझे निम्न समस्या मिल गई है:

जब मेरे यूआईटीबल दृश्य स्क्रॉल करें और नीचे, उसके बाद मैं इनपुटटेक्स्टफ़ील्ड में टेक्स्ट जोड़ता हूं, तो उस सामग्री को "माइग्रेट करता है" दूसरे UITableViewCell

मेरे कोड में क्या गलत है?

<पी > मुझे लगता है कि आपकी 'समस्या' यह है कि कोशिकाओं का पुन: उपयोग किया जाता है और उनका पुन: उपयोग करने से पहले उनकी सामग्री कभी भी रीसेट नहीं होती है।

या तो readyForReuse के साथ पुन: उपयोग किए जाने से पहले कोशिकाओं को तैयार करें ) / या cellForRowAtIndexPath में इनपुट फ़ील्ड साफ़ करें

एप्पल के दिशानिर्देशों के मुताबिक, इसका पसंदीदा तरीका (सेल सामग्री के लिए) cellForRowAtIndexPath

निष्पादन के कारणों के लिए, आपको केवल उस कक्ष की विशेषताओं को रीसेट करना चाहिए जो सामग्री से संबंधित नहीं हैं, उदाहरण के लिए, अल्फा, संपादन और चयन स्थिति। टेबल दृश्य में तालिका दृश्य का प्रतिनिधि: cellForRowAtIndexPath: हमेशा एक सेल का उपयोग करते समय सभी सामग्री को रीसेट कर देना चाहिए।

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -