Reputation: 2294
i have a table view and i am adding some labels to uitableview cell and the actual screen is as follows
and while scrolling 2-3 times it will appear as follows
and the code is as follows
and code is as follows
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell;
static NSString *CellIdentifier = @"Cell";
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
cell.selectionStyle=UITableViewCellSelectionStyleNone;
switch (indexPath.section) {
case 0:{
[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
NSString *drugName;
if ([responsePrecDetails.drugName length]>0) {
NSString *startDrugName=[[responsePrecDetails.drugName substringToIndex:1] uppercaseString];
NSString *endDrugName=[[responsePrecDetails.drugName substringFromIndex:1] lowercaseString];
drugName=[NSString stringWithFormat:@"%@%@",startDrugName,endDrugName];
}
else {
drugName=@"NA";
}
UILabel *lblPrescName = [self createCustomDynamicLabel:drugName
color:[UIColor walgreensRedColor]
fontsize:14
fontName:@"HelveticaNeue-Bold"
contentframe:CGRectMake(10,10,250 ,20)];
[cell.contentView addSubview:lblPrescName];
[lblPrescName release];
break;
}
case 1:{
if (indexPath.row==0 && [responsePrecDetails.status length]>0) {
UILabel *lblStatus = [self createCustomDynamicLabel:@"Status:"
color:[UIColor customisedblackColor]
fontsize:14
fontName:@"HelveticaNeue-Bold"
contentframe:CGRectMake(10,10,60 ,20)];
[cell.contentView addSubview:lblStatus];
[lblStatus release];
UILabel *lblStatusAns = [self createCustomDynamicLabel:responsePrecDetails.status
color:[UIColor customisedgreysColor]
fontsize:14
fontName:@"HelveticaNeue"
contentframe:CGRectMake(60,10,120,20)];
[cell.contentView addSubview:lblStatusAns];
[lblStatusAns release];
}
else {
UILabel *lblDrName = [self createCustomDynamicLabel:@"Dr "
color:[UIColor customisedblackColor]
fontsize:14
fontName:@"HelveticaNeue-Bold"
contentframe:CGRectMake(10,7,25 ,20)];
[cell.contentView addSubview:lblDrName];
[lblDrName release];
UILabel *lblDrNameAns = [self createCustomDynamicLabel:[responsePrecDetails.rxer capitalizedString]
color:[UIColor customisedgreysColor]
fontsize:14
fontName:@"HelveticaNeue"
contentframe:CGRectMake(30,7,150 ,20)];
[cell.contentView addSubview:lblDrNameAns];
[lblDrNameAns release];
UILabel *lblName = [self createCustomDynamicLabel:@"For: "
color:[UIColor customisedblackColor]
fontsize:14
fontName:@"HelveticaNeue-Bold"
contentframe:CGRectMake(10,26,40 ,20)];
[cell.contentView addSubview:lblName];
[lblName release];
UILabel *lblNameAns = [self createCustomDynamicLabel:[responsePrecDetails.patientName capitalizedString]
color:[UIColor customisedgreysColor]
fontsize:14
fontName:@"HelveticaNeue"
contentframe:CGRectMake(40,26,120 ,20)];
[cell.contentView addSubview:lblNameAns];
[lblNameAns release];
UILabel *lblDirections = [self createCustomDynamicLabel:@"Directions For Use: "
color:[UIColor customisedblackColor]
fontsize:14
fontName:@"HelveticaNeue-Bold"
contentframe:CGRectMake(10,44,230 ,20)];
[cell.contentView addSubview:lblDirections];
[lblDirections release];
NSString *directionOfUse;
NSLog(@"dirctionofuse=%@",responsePrecDetails.directionOfUse);
if ([responsePrecDetails.directionOfUse length]>0) {
NSString *startDirectionOfUse=[[responsePrecDetails.directionOfUse substringToIndex:1] uppercaseString];
NSString *endDirectionOfUse=[[responsePrecDetails.directionOfUse substringFromIndex:1] lowercaseString];
directionOfUse=[NSString stringWithFormat:@"%@%@",startDirectionOfUse,endDirectionOfUse];
}
else {
directionOfUse=@"NA";
}
UILabel *lblDirectionsAns = [self createCustomDynamicLabel:directionOfUse
color:[UIColor customisedgreysColor]
fontsize:14
fontName:@"HelveticaNeue"
contentframe:CGRectMake(150,35,284 ,35)];
lblDirectionsAns.lineBreakMode = UILineBreakModeWordWrap;
lblDirectionsAns.numberOfLines = 2;
[cell.contentView addSubview:lblDirectionsAns];
[lblDirectionsAns release];
UILabel *lblRefills = [self createCustomDynamicLabel:@"Refills:"
color:[UIColor customisedblackColor]
fontsize:14
fontName:@"HelveticaNeue-Bold"
contentframe:CGRectMake(10,92,50 ,20)];
[cell.contentView addSubview:lblRefills];
[lblRefills release];
UILabel *lblRefillsAns=[self createCustomDynamicLabel:[responsePrecDetails.totalRfl stringByReplacingOccurrencesOfString:@"-" withString:@"/"]
color:[UIColor customisedgreysColor]
fontsize:14
fontName:@"HelveticaNeue"
contentframe:CGRectMake(60,92,150 ,20)];
[cell.contentView addSubview:lblRefillsAns];
[lblRefillsAns release];
UILabel *lblPickupLocations=[self createCustomDynamicLabel:@"Pickup Location:"
color:[UIColor customisedblackColor]
fontsize:14
fontName:@"HelveticaNeue-Bold"
contentframe:CGRectMake(10,110,150 ,20)];
[cell.contentView addSubview:lblPickupLocations];
[lblPickupLocations release];
UILabel *lblPickupLocationsAns = [self createCustomDynamicLabel:responsePrecDetails.pickupSore
color:[UIColor customisedgreysColor]
fontsize:14
fontName:@"HelveticaNeue"
contentframe:CGRectMake(10,130,250 ,43)];
lblPickupLocationsAns.lineBreakMode = YES;
lblPickupLocationsAns.numberOfLines = 2;
[cell.contentView addSubview:lblPickupLocationsAns];
[lblPickupLocationsAns release];
UILabel *lblPhoneNo = [self createCustomDynamicLabel:responsePrecDetails.phoneNo
color:[UIColor customisedlightBlueColor]
fontsize:14
fontName:@"HelveticaNeue-Bold"
contentframe:CGRectMake(50,180,100 ,20)];
[cell.contentView addSubview:lblPhoneNo];
[lblPhoneNo release];
// UILabel *lblDistance = [self createCustomDynamicLabel:responsePrecDetails.distance
// color:[UIColor customisedlightBlueColor]
// fontsize:14
// fontName:@"HelveticaNeue-Bold"
// contentframe:CGRectMake(220,175,80 ,20)];
//
// [cell.contentView addSubview:lblDistance];
// [lblDistance release];
// UIImageView *miles = [[UIImageView alloc] init];
// miles.frame = CGRectMake(180, 170, 30, 30);
// miles.image = [UIImage imageNamed:@"Images.bundle/Images/Flushot/[email protected]"];
// [cell.contentView addSubview:miles];
// [miles release];
UIImageView *phone = [[UIImageView alloc] init];
phone.frame = CGRectMake(10, 177, 30, 30);
phone.image = [UIImage imageNamed:@"Images.bundle/Images/Flushot/[email protected]"];
[cell.contentView addSubview:phone];
[phone release];
}
break;
default: {
UILabel *cellLbl =[[UILabel alloc] init];
cellLbl.frame=CGRectMake(0,0, 320, 55);
orderInfo *prescInfo= [responsePrecDetails.order objectAtIndex:indexPath.section-2];
UILabel *lblQty=[self createCustomDynamicLabel:@"Qty: "
color:[UIColor customisedgreysColor]
fontsize:14
fontName:@"HelveticaNeue-Bold"
contentframe:CGRectMake(5,5,35 ,18)];
[cellLbl addSubview:lblQty];
[lblQty release];
UILabel *lblPrice=[self createCustomDynamicLabel:@"Price: "
color:[UIColor customisedgreysColor]
fontsize:14
fontName:@"HelveticaNeue-Bold"
contentframe:CGRectMake(5,23,50 ,18)];
[cellLbl addSubview:lblPrice];
[lblPrice release];
UILabel *lblIns=[self createCustomDynamicLabel:@"Insurance: "
color:[UIColor customisedgreysColor]
fontsize:14
fontName:@"HelveticaNeue-Bold"
contentframe:CGRectMake(5,38,80 ,20)];
[cellLbl addSubview:lblIns];
[lblIns release];
UILabel *lblQtyAns=[self createCustomDynamicLabel:prescInfo.orderQty
color:[UIColor customisedgreysColor]
fontsize:14
fontName:@"HelveticaNeue"
contentframe:CGRectMake(45,5,150 ,18)];
[cellLbl addSubview:lblQtyAns];
[lblQtyAns release];
UILabel *lblPriceAns=[self createCustomDynamicLabel:[NSString stringWithFormat:@"$ %@",prescInfo.lastFlPrc]
color:[UIColor customisedgreysColor]
fontsize:14
fontName:@"HelveticaNeue"
contentframe:CGRectMake(55,23,150 ,18)];
[cellLbl addSubview:lblPriceAns];
[lblPriceAns release];
UILabel *lblInsAns=[self createCustomDynamicLabel:prescInfo.ins
color:[UIColor customisedgreysColor]
fontsize:14
fontName:@"HelveticaNeue"
contentframe:CGRectMake(85,38,150 ,20)];
[cellLbl addSubview:lblInsAns];
[lblInsAns release];
cell.backgroundView = cellLbl;
[cellLbl release];
break;
}
}
}
}
return cell;
}
can any one please help me what is the problem inscrolling the uitable view
Upvotes: 0
Views: 152
Reputation: 29767
What is the reason to release
this object?
UILabel *lblStatus = [self createCustomDynamicLabel:...];
[cell.contentView addSubview:lblStatus];
[lblStatus release];
Remove last line if you receive autoreleased label object from createCustomDynamicLabel
method
Upvotes: 2
Reputation: 64
You need to define the Cell Identifier inside Switch cases. Its overlapping because all the cells are using single Identifier and tableview reads them from Cache.
Upvotes: 0