2011-12-04 20 views
8

में दिखाता है मैंने इंटरफेस बिल्डर (स्टोरीबोर्ड) में एक कस्टम UITableViewCell बनाया और #import CustomTableViewCell.h के माध्यम से इसे अपने प्रोजेक्ट में आयात किया।कस्टम UITableViewCell (आईबी) केवल चयनित राज्य

सबकुछ ठीक काम करता है, लेकिन सेल केवल चयनित राज्य में लोड होता है।

enter image description here

मैं सेल init द्वारा प्रत्येक पंक्ति में लोड किया जा करना चाहते हैं।

पीएस स्लाइडर और टेक्स्ट फ़ील्ड कनेक्शन ठीक काम करते हैं। मैंने सभी आईबी कनेक्शन भी बनाए।

CustomTableViewCell.m

#import "CustomTableViewCell.h" 

@implementation CustomTableViewCell 

@synthesize sliderLabel, slider; 

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier 
{ 
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; 
if (self) { 
    // Initialization code 
} 
return self; 
} 

- (void)setSelected:(BOOL)selected animated:(BOOL)animated 
{ 
[super setSelected:selected animated:animated]; 

// Configure the view for the selected state 

} 

- (IBAction)getSliderValuesWithValue:(UISlider *)sender 
{ 
sliderLabel.text = [NSString stringWithFormat:@"%i/100", (int) roundf(sender.value)]; 
} 

@end 

Further Code

- (CustomTableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
static NSString *CellIdentifier = @"Kriterium"; 

CustomTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) { 
    cell = [[CustomTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
} 

// Configure the cell... 

cell.textLabel.text = [NSString stringWithFormat:@"%@", [listOfItems objectAtIndex:indexPath.row]]; 

return cell; 
} 

पी.एस. अगर मैं उपरोक्त विधि में कुछ बटन आदि प्रोग्रामेटिक रूप से जोड़ता हूं तो यह काम करता है। लेकिन मैं आईबी में पंक्तियों को डिजाइन करना चाहता हूं। एक समाधान होना है।

+0

क्या आप पंक्तियों के साथ UITableView को पॉप्युलेट करते समय अपने सेलफॉररोएट इंडेक्सपैथ विधि के लिए कोड पोस्ट कर सकते हैं? – reddersky

+0

मैंने अपना जवाब अपडेट किया। – DAS

+0

क्या आपने इस सेल को स्टोरीबोर्ड में टेबल व्यू के भीतर एक अलग निब में या प्रोटोटाइप के रूप में डिज़ाइन किया है? – jrturton

उत्तर

16

ठीक है ... अजीब यहाँ हो रहा बातें ... ;-) समस्या इस लाइन थी। मुझे अपने कस्टमसेल में एक और UILabel जोड़ना पड़ा जो मैं पाठ से भरता हूं।

निष्कर्ष

मानक UITableViewCell.textLabel.text भरने PrototypeCells के ऊपर लिख रहा है।

... बहुत अधिक अनुकूलन दर्द होता है। ;-)

वैसे भी धन्यवाद! :)

+0

क्या आपका मतलब मेरे समाधान में है या आम तौर पर? फिर से धन्यवाद जूनियर! – DAS

+0

मेरा मतलब आम तौर पर - यदि आप डिफ़ॉल्ट सेल शैली का उपयोग करते हैं तो इसके लिए सबव्यू जोड़ें, यह शायद कुछ देखने के लिए है। – jrturton

+0

ठीक है, धन्यवाद। ऐसा इसलिए है क्योंकि मुझे विभिन्न सेल शैलियों का एक गुच्छा चाहिए। आईबी में उन्हें कल्पना करना मेरे लिए आसान है। :) – DAS

0

आपको आईबी के लिए जाने का सुझाव नहीं है। बस संपत्ति के रूप में और अपने init method- initWithStyle (CustomTableViewCell.m फ़ाइल) में उन नियंत्रणों को परिभाषित के डिफ़ॉल्ट गुण के साथ UISlider प्रारंभ:

UISlider *tempSlider = [[UISlider alloc] initWithFrame:frame]; 
tempSlider.selected = NO; 
//define other properties as well 
self.slider = tempSlider; 
[self addSubview:self.slider]; 
[tempSlider release]; 

इसके अलावा आप भी किसी से सेल चयन शैली सेट कर सकते हैं।

cell.textLabel.text = [NSString stringWithFormat:@"%@", [listOfItems objectAtIndex:indexPath.row]]; 

यह चाल बाहर छोड़कर था:

cell.selectionStyle = UITableViewCellSelectionStyleNone; 
+0

धन्यवाद। लेकिन इसे मूल रूप से [यह (क्लिक)] (http://www.raywenderlich.com/5138/beginning-storyboards-in-ios-5-part-1) जैसे काम करना है।हर कोई इस लाइन का उपयोग करता है जो मेरी समस्या पर कुछ भी नहीं बदलता है: 'UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier: @ "PlayerCell"]; ' – DAS

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