मेरे पास UITableViewCell में तीन कस्टम UILabel हैं। इस तरह सेल डिजाइन,आईफोन में गतिशील रूप से UITableviewCell ऊंचाई बदलें?
Date(12.1.2012) Time(12.00pm)
Cost: $20.00
Details
मैं - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
में पंक्ति की ऊँचाई निर्दिष्ट किया है 100। लेकिन, अब विवरण कुछ समय सर्वर से खाली (शून्य) वापस आते हैं। उस समय मुझे सेल से विवरण लेबल को हटाने और विशेष सेल (पंक्ति) ऊंचाई 70 तक बदलने की आवश्यकता है। मैं यह कैसे कर सकता हूं? मैंने Google में अपना स्तर सबसे अच्छा खोजा। लेकिन, मैं अभी भी यह करने के लिए उलझन में हूँ। क्या आप मेरी मदद कर सकते हैं? धन्यवाद। मुझे इस लिंक से कुछ विचार मिला - http://www.cimgf.com/2009/09/23/uitableviewcell-dynamic-height/
। उन्होंने पंक्ति ऊंचाई का आकार बदलने के लिए केवल एक लेबल का उपयोग किया। क्रिप्या मेरि सहायता करे।
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 90;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
UILabel *dateLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 100, 30)];
dateLabel.tag = 100;
dateLabel.backgroundColor = [UIColor clearColor];
dateLabel.font = [UIFont fontWithName:@"Helvetica" size:16];
dateLabel.font = [UIFont boldSystemFontOfSize:16];
dateLabel.highlightedTextColor = [UIColor whiteColor];
[cell.contentView addSubview: dateLabel];
UILabel *timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(120, 0, 200, 25)];
timeLabel.tag = 101;
timeLabel.backgroundColor = [UIColor clearColor];
timeLabel.font = [UIFont fontWithName:@"Helvetica" size:14];
timeLabel.highlightedTextColor = [UIColor whiteColor];
[cell.contentView addSubview: timeLabel];
UILabel *costLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 30, 300, 25)];
costLabel.tag = 102;
costLabel.backgroundColor = [UIColor clearColor];
costLabel.font = [UIFont fontWithName:@"Helvetica" size:14];
costLabel.font = [UIFont boldSystemFontOfSize:14];
costLabel.highlightedTextColor = [UIColor whiteColor];
[cell.contentView addSubview: costLabel];
UILabel *eventLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 60, 300, 25)];
eventLabel.tag = 103;
eventLabel.backgroundColor = [UIColor clearColor];
eventLabel.font = [UIFont fontWithName:@"Helvetica" size:14];
eventLabel.font = [UIFont boldSystemFontOfSize:14];
eventLabel.highlightedTextColor = [UIColor whiteColor];
[cell.contentView addSubview: eventLabel];
}
UILabel *dateLabel = (UILabel *) [cell.contentView viewWithTag:100];
dateLabel.text = [DateArray objectAtIndex:indexPath.row];
UILabel * timeLabel = (UILabel *) [cell.contentView viewWithTag:101];
timeLabel.text = [timeArray objectAtIndex:indexPath.row];
UILabel * costLabel = (UILabel *) [cell.contentView viewWithTag:102];
costLabel.text = [costArray objectAtIndex:indexPath.row];
UILabel *eventLabel = (UILabel *) [cell.contentView viewWithTag:103];
NSString *description = [eventArray objectAtIndex:indexPath.row];
if([description isEqualToString:@""])
{
eventLabel.text = @""; // Here i don't want to show this label and resize(reduce) the row height to 60;
}
else
{
eventLabel.text = description;
}
return cell;
}
मैं यह कैसे कर सकता हूं? धन्यवाद।
श्री माधवनआरपी आपके उत्तर के लिए धन्यवाद। मैंने आपके कोड में आपके उत्तर की कोशिश की है। मैंने cellForRowAtIndexPath में भी स्थिति की जांच की है: भी। पहली बार यह ठीक काम कर रहा है। जब मैं टेबलव्यू स्क्रॉल करता हूं, तो सेल आकार बदल गया है और वर्णन लेबल ने स्थान बदल दिया है। इसका मतलब है कि विवरण पंक्ति सभी पंक्तियों के लिए हटा दी गई है। क्या आप मेरी मदद कर सकते हैं। धन्यवाद – Gopinath
@ गोपीनाथ क्यों आप विवरण के लेबल को केवल सेल विवरण के रूप में जोड़ने का प्रयास नहीं करते हैं जब आपके पास कुछ विवरण होता है। स्क्रॉलिंग समस्या को हल करने के लिए आपको कस्टम क्लास बनाने की आवश्यकता हो सकती है। इस प्रश्न का उत्तर देखें http://stackoverflow.com/questions/8352530/changing-the-position-of-custom-uibutton-in-custom-uitableviewcell – MadhavanRP