XIB

2011-02-26 12 views
8

का उपयोग किये बिना कस्टम UITableViewCell कैसे बनाएं I XIB का उपयोग करके कस्टम टेबल व्यू सेल बनाने के तरीके पर इतने सारे ट्यूटोरियल मिले, लेकिन क्या XIB का उपयोग किए बिना कस्टम टेबल व्यू सेल बनाना संभव है? क्या कोई मेरी मदद कर सकता है?XIB

उत्तर

5

हाँ, आप XIB का उपयोग किए बिना कस्टम टेबल व्यू सेल बना सकते हैं।

इसके लिए, आपको UCDableViewCell के उप-वर्ग के साथ एक्सकोड में एक नई कक्षा बनाना है। यहां आप किसी भी XIB विकल्पों का चयन नहीं कर सकते हैं।

अब अपने कस्टम UITableViewCell वर्ग खोलने के लिए और यहाँ कोड प्राप्त होगा कि तुम क्या चाहते हो:

#import "CustomCell.h" 

@implementation CustomCell 

@synthesize ivUser; 
@synthesize lblUserName; 

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier: 
(NSString *)reuseIdentifier 

{ 

    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; 
     if (self) { 
      // Initialization code 

     ivUser = [[UIImageView alloc] initWithFrame:CGRectMake(4.0f, 3.0f, 39.0f, 
     38.0f)]; 
     lblUserName = [[UILabel alloc] initWithFrame:CGRectMake(58.0f, 8.0f, 50.0f, 
     27.0f)]; 

     [self.contentView addSubview:ivUser]; 
     [self.contentView addSubview:lblUserName]; 

    } 

    return self; 
} 

अपने subviews अब सेट आवश्यकता के अनुसार निर्देशांक, तो अपने CellForRowAtIndexPath में इस सेल का उपयोग करें और यह काम करना चाहिए।

+2

मेरे tableviewcontroller में, मेरा myCellIdentifier यहां क्या होना चाहिए: 'कस्टमसेल * सेल = [tableView dequeueReusableCellWithIdentifier: @" myCellIdentifier "];'? – zengr

+2

निम्नलिखित में शामिल करेंडिडलोड: '[self.tableView रजिस्टर क्लास: [कस्टमसेल क्लास] के लिएसेलर्यूजइडिएंटिफायर: @" myCellIdentifier "];' –

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