2012-03-06 10 views
5

का सेल वापस नहीं लौटा रहा है मैं UITableViewCellroller के साथ UITableViewController के साथ iOS5 स्टोरीबोर्ड का उपयोग कर रहा हूं। मैं दृश्य के लिए स्टोरीबोर्ड डिजाइनर में सेल के दृश्य तत्वों को डिज़ाइन नहीं करना चाहता, क्योंकि मैं UITableViewCell (विशेष रूप से TDBadgedCell) के पुन: प्रयोज्य उप-वर्ग का उपयोग करना चाहता हूं।dequeueReusableCellWithIdentifier मेरे कस्टम प्रकार

मैंने स्टोरीबोर्ड डिजाइनर में अपना सेल पहचानकर्ता सेट किया है, और जब तक मैं TDBadgedCell के लिए अद्वितीय गुणों को सेट नहीं कर रहा हूं, तब तक सभी पंक्तियां UITableView में सही ढंग से लोड होती हैं। अगर मैं badgeString संपत्ति सेट करता हूं जो कि TDBadgedCell के लिए अद्वितीय है, तो मुझे अपवाद मिलता है। मैंने संकुचित किया कि dequeueReusableCellWithIdentifier: TDBadgedCell प्रकार के सेल को वापस नहीं कर रहा है।

मैं केवल UITableViewController के साथ इसमें चल रहा हूं। मेरे पास एक UIViewController है जो एक एम्बेडेड UITableView के साथ एक ही फैशन में स्थापित है और यह कोई समस्या नहीं है। कोई विचार?

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath 
{ 
static NSString *CellIdentifier = @"PhoneNumberCell"; 
TDBadgedCell *cell = (TDBadgedCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

if (cell == nil) { 
    cell = [[TDBadgedCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
} 

if ([cell isKindOfClass:[TDBadgedCell class]]) 
{ 
    NSLog(@"It is TDBadgedCell"); 
} 
else 
    NSLog(@"It is NOT TDBadgedCell"); 
+6

क्या आपने स्टोरीबोर्ड डिजाइनर में "कस्टम क्लास" को TDBadgedCell भी बदल दिया है? – fengd

+0

[स्टोरीबोर्ड के बजाए एक निब में प्रोटोटाइप सेल का संभावित डुप्लिकेट] (http://stackoverflow.com/questions/8574188/prototype-cells-in-a-nib-instead-of-a-storyboard) - केवल संभव है, मुझे यकीन नहीं है कि आपके पास इस सेल के लिए एक अलग xib है या नहीं। – jrturton

+0

जून 1 - वह था! धन्यवाद! मुझे यकीन नहीं है कि उत्तर के रूप में आपके उत्तर को कैसे चिह्नित करें। – scubasteve

उत्तर

0

मुझे एक समान समस्या थी कि मैं UITableViewCell subclassing लेकिन स्टोरीबोर्ड का उपयोग नहीं कर रहा हूं। यदि उपयोगकर्ता ने ऐप की अनलॉक सुविधा खरीदी है तो इस पर निर्भर विभिन्न सेल वर्गों का उपयोग करने का मेरा समाधान यहां दिया गया है। उम्मीद है कि यह किसी की मदद करता है।

संक्षेप में, मेरे पास UITextView ऑब्जेक्ट सहित कई ऑब्जेक्ट्स वाला सेल था। मैं लाइट संस्करण में UITextView ऑब्जेक्ट की कॉपी और पेस्ट फीचर को लॉक करना चाहता था, फिर उपयोगकर्ता ने इन-एप उत्पाद में खरीदे जाने के बाद सुविधा को रिलीज़ करना चाहता था।

मेरे पास दो UITableViewCell कक्षाएं थीं, एक यूआईटीएक्स्टव्यू के साथ एक है और दूसरा यूआईटीएक्स्टव्यू के साथ सबक्साइड किया जा सकता है भविष्यवाणियों को वापस लौटना। इस तरह उपयोगकर्ता अभी भी UITextview डेटा को ऊपर और नीचे स्क्रॉल कर सकता है लेकिन डेटा कॉपी और पेस्ट नहीं कर सकता है।

यहां कोड है और मुझे बस इतना करना था कि पुन: उपयोग पहचानकर्ताओं का नाम बदलें।

क्यों? क्योंकि [self.tableview reloadData] कोशिकाओं को नए वर्ग के साथ पुनर्निर्माण नहीं करेगा क्योंकि सेल अभी भी अस्तित्व में था। स्क्रीन से नई कोशिकाओं को नई कक्षा मिल जाएगी लेकिन मौजूदा लोग नहीं होंगे। यह समाधान अतिरिक्त सुविधा को अनलॉक करने के बाद खरीदारी के बाद एक बार सभी कोशिकाओं का पुनर्निर्माण करता है।

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


if (your test if in-app was purchased is yes) 
{ 
static NSString *MyIdentifier = @"MyCell"; 

FrontCell *cell = (FrontCell *)[tableView dequeueReusableCellWithIdentifier:MyIdentifier]; 

if (cell == nil) 
     { 
     cell = [[FrontCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier]; 
     cell.selectionStyle = UITableViewCellSelectionStyleNone; 
     cell.shouldIndentWhileEditing = NO; 
    } 

//....///  

cell.trackDetails.text = [yourObject objectAtIndex:indexPath.row]; 
cell.trackDetails.delegate = self; 
cell.trackDetails.tag = indexPath.row; 


return cell; 
} 
else // inapp not purchased 
{ 
    static NSString *MyLockedIdentifier = @"MyLockedCell"; 

    FrontCellLocked *cell = (FrontCellLocked *)[tableView dequeueReusableCellWithIdentifier:MyLockedIdentifier]; 

    if (cell == nil) 
    { 
     cell = [[FrontCellLocked alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyLockedIdentifier]; 
     cell.selectionStyle = UITableViewCellSelectionStyleNone; 
     cell.shouldIndentWhileEditing = NO; 
    } 

    //....///  

cell.trackDetails.text = [yourObject objectAtIndex:indexPath.row]; 
cell.trackDetails.delegate = self; 
cell.trackDetails.tag = indexPath.row; 


return cell; } 
} 
0

स्टोरीबोर्ड में, आप कस्टम क्लास प्रॉपर्टी को UITablviewCell के उप-वर्ग के लिए सेट कर सकते हैं।
फिर dequeueReusableCellWithIdentifier विधि आपके उप-वर्ग के प्रकार के साथ सेल वापस कर देगा।

0

मुझे लगता है कि आप कोशिकाओं को हटाने के लिए गलत विधि का उपयोग कर रहे हैं।

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 
    UITableViewCell *cell = [self.tblProfileInfo dequeueReusableCellWithIdentifier:@"PostCell" forIndexPath:indexPath]; 
    cell.selectionStyle = UITableViewCellSelectionStyleNone; 
    return cell; 

} 

आप अंत में इंडेक्सपाथ के लिए भूल गए हैं।

+0

"TDBadgedCell * सेल = (TDBadgedCell *) को बदलने का प्रयास करें [tableView dequeueReusableCellWithIdentifier: CellIdentifier];" "TDBadgedCell * सेल = (TDBadgedCell *) [tableView dequeueReusableCellWithIdentifier: CellIdentifier forndexPath: indexPath];" –

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