2012-11-06 13 views
7

मेरे पास एक प्रोग्राम है जिसमें एक टेबल व्यू कंट्रोलर है जिसमें 1 सेक्शन और 3 पंक्तियां हैं। जब भी मैं ऐप चलाता हूं, यह हमेशा dequeueReusableCellWithIdentifier: विधि पर दुर्घटनाग्रस्त हो जाता है। मैंने इस विधि में ब्रेकपॉइंट और NSLog() शून्य पर डाला। मैंने स्टोरीबोर्ड में प्रोटोटाइप सेल के पर Cell Identifier भी सेट किया है। लेकिन कार्यक्रम अभी भी दुर्घटनाग्रस्त है। यहाँ एक विधि है कि समस्या का कारण है है:प्रोग्राम deckueReusableCellWithIdentifier पर क्रैश:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    NSLog(@"indexPath.section = %d, indexPath.row = %d", indexPath.section, indexPath.row); 
    static NSString *CellIdentifier = @"Cell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; 

    if (cell == nil) 
    { 
     NSLog(@"in nil"); 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]; 
    } 

    return cell; 
} 

क्रैश लॉग पढ़ता है:

MyAppTake4[7463:707] indexPath.section = 0, indexPath.row = 0 
2012-11-05 23:21:20.747 MyCardAppTake4[7463:707] -[UITableView  dequeueReusableCellWithIdentifier:forIndexPath:]: unrecognized selector sent to instance  0xfbc9000 
2012-11-05 23:21:20.753 MyCardAppTake4[7463:707] *** Terminating app due to uncaught  exception 'NSInvalidArgumentException', reason: '-[UITableView  dequeueReusableCellWithIdentifier:forIndexPath:]: unrecognized selector sent to instance  0xfbc9000' 
*** First throw call stack: 
(0x3254788f 0x3459d259 0x3254aa9b 0x32549915 0x324a4650 0x7e2f7 0x31fceefb 0x31fcdfd9  0x31fcd763 0x31f71f15 0x324a61fb 0x3420aaa5 0x3420a6bd 0x3420e843 0x3420e57f 0x342064b9  0x3251bb1b 0x32519d57 0x3251a0b1 0x3249d4a5 0x3249d36d 0x315f4439 0x31f9ccd5 0x7d9f9 0x7d994) 
terminate called throwing an exception(lldb) 

मैं त्रुटि का सही कारण की पहचान ताकि मैं इस गलती को फिर से नहीं कर सकता हूँ में दिलचस्पी है।

आपकी मदद के लिए धन्यवाद।

+1

'UITableView' विधि 'dequeueReusableCellWithIdentifier: for इंडेक्सपैथ:' आईओएस 6.0 में जोड़ा गया था। क्या आपको यह त्रुटि आईओएस 5.x के तहत मिल रही है? – rmaddy

उत्तर

9

Thats क्योंकि [tableView dequeueReusableCellWithIdentifier: CellIdentifier forndexPath: indexPath]; iOS 6 में जोड़ा गया, लेकिन इसके बजाय विधि नीचे आईओएस 5. द्वारा मान्यता प्राप्त नहीं iOS 5 संगतता उपयोग के लिए:

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
+5

'dequeueReusableCellWithIdentifier: इंडेक्सपैथ के लिए:' आईओएस 6.0 के रूप में एक पूरी तरह से वैध विधि है। – rmaddy

+3

धन्यवाद साइबरपॉर्न .. यह काम किया। बस 'इंडेक्सपैथ: इंडेक्सपाथ' को हटाने के लिए, प्रोग्राम ने काम करना शुरू कर दिया। यह विधि डिफ़ॉल्ट रूप से मौजूद थी जब मैंने 'UITableViewController' के उप-वर्ग के साथ एक नई फ़ाइल बनाई थी। यदि 'इंडेक्सपेथ: इंडेक्सपाथ' अपराधी है, तो यह डिफ़ॉल्ट रूप से प्रोग्राम में क्यों मौजूद है? –

+0

आपकी टिप्पणी के बाद से पहले मुझे समस्या की पहचान करने में मदद मिली, मैंने आपका जवाब स्वीकार कर लिया है। मैं रोपिंग के लिए दूसरे का भी आभारी हूं! :-) –

7

आप सेल या निब पहले के वर्ग रजिस्टर किया था?

एप्पल डॉक्स से:

महत्वपूर्ण: इस विधि कॉल करने से पहले विधि: forCellReuseIdentifier: या registerClass: forCellReuseIdentifier आप registerNib का उपयोग कर एक वर्ग या निब फ़ाइल रजिस्टर करना होगा।

(Btw कि विधि IOS 6 में ही उपलब्ध है)

आप IOS 6 का उपयोग कर रहे हैं, तो आप नया सरल प्रतिमान का उपयोग कर सकते हैं:

viewDidLoad में, वर्ग रजिस्टर, अपने मामले में तब

[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"Cell"]; 

, तो आप सिर्फ cellForRowAtIndexPath में इस तरह यह कर सकते हैं:, यह सिर्फ UITableViewCell वर्ग है

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

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath]; 
    cell.textLabel.text = self.myArray[indexPath.row]; 
    return result; 
} 
+0

मैंने व्यू कंट्रोलर की कक्षा पंजीकृत की थी। मैं स्टोरीबोर्ड का उपयोग कर रहा हूं क्योंकि कोई 'nib' नहीं है। 'साइबरपाउन' ने मुझे त्रुटि खोजने में मदद की। आपकी सहायता के लिए धन्यवाद. –

+0

महान .. मैं दिमाग में दिमाग रखूंगा! –

+0

मेरे 'viewDidLoad' में 'registerClass' विधि जोड़ना मेरे लिए चाल था। धन्यवाद। –

1

चूंकि इंडेक्सपैथ विधि ios6 के लिए है, इसलिए मैं आपको इस स्निपेट का उपयोग करने की सलाह देता हूं। नीचे ढूँढो।

UITableViewCell *cell = [table_view dequeueReusableCellWithIdentifier:@"cell"]; 
if (cell == nil) 
{ 
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"]; 

    // **initialize** your stuff here **with their respected tag** 
} 
else 
{ 
    // **get** your stuff back using their tags 
} 
// **assign** your valiues here 

return cell; 

प्रोग्रामिंग

+0

धन्यवाद फोराम मुकुंद शाह! –

0

मैं इस अपवाद था आनंद लें, और महसूस किया कि यह मेरा बेवकूफ गलती की वजह से किया गया था। मैंने एक खाली .xib फ़ाइल बनाई है (मेरे UITableView में एक कस्टम "लोडिंग" सेल रखने के लिए), लेकिन उसके बाद View को ड्रैग नहीं किया था। रवींद्र!

परिणाम जो आप देख रहे हैं अपवाद संदेश था, के साथ साथ इस आउटपुट विंडो में:

2014-04-25 20:45:12.953 Languages[36256:60b] *** Terminating app due to uncaught 
exception 'NSInternalInconsistencyException', reason: 'invalid nib registered 
for identifier (LoadingCell) - nib must contain exactly one top level object 
which must be a UITableViewCell instance' 

समाधान, ज़ाहिर है, था मेरी .xib फाइल करने के लिए एक Table View Cell जोड़ने के लिए, दूसरे की नकल यूआई घटकों में, और फ़ाइल में "रूट" तत्व के रूप में बस उस तालिका दृश्य कक्ष को छोड़ दें।

+0

हाँ, मैंने गलती से वही किया। मेरी .xib फ़ाइल सही थी ... लेकिन मैं गलती से .xib पर एक लेबल को ड्रैग नहीं किया था, बाहर के बाहर मुख्य दृश्य। (Sigh।) एक और बर्बाद घंटे चाक। –

0

इस त्रुटि के लिए एक अन्य कारण है- सकते

अमान्य पहचानकर्ता (सेल) के लिए पंजीकृत निब - निब ठीक एक शीर्ष स्तर वस्तु जो एक UICollectionReusableView उदाहरण

मैं अपने xib में एक UIView था होना चाहिए शामिल होना चाहिए संग्रह ViewCell के बजाय। उम्मीद है की यह मदद करेगा।

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