Wednesday, 18 April 2012

adding labels in cell programatically

- (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];
    //}
   
    // Configure the cell...
    //codee=[[ArrPOList objectAtIndex:indexPath.row] objectAtIndex:7];
    //NSLog(@"FFF--%@",codee);
   
    UILabel *lbl = [[UILabel alloc] initWithFrame:CGRectMake(5.0, 2.0, 170.0, 20.0)];
    lbl.font=[UIFont boldSystemFontOfSize:13.0];
    lbl.textColor = [UIColor blackColor];
    lbl.backgroundColor = [UIColor clearColor];
    lbl.highlightedTextColor = [UIColor whiteColor];
    lbl.text = [[ArrPOList objectAtIndex:indexPath.row] objectAtIndex:2];
    [cell.contentView addSubview:lbl];
   
    lbl = [[UILabel alloc] initWithFrame:CGRectMake(170, 2.0, 120.0, 20.0)];
    lbl.font=[UIFont boldSystemFontOfSize:12.0];
    lbl.textAlignment = UITextAlignmentRight;
    lbl.textColor = [UIColor blackColor];
    lbl.backgroundColor = [UIColor clearColor];
    lbl.highlightedTextColor = [UIColor whiteColor];
    lbl.text =[NSString stringWithFormat:@"%.2f %@", [[[ArrPOList objectAtIndex:indexPath.row] objectAtIndex:4] doubleValue],[[ArrPOList objectAtIndex:indexPath.row] objectAtIndex:5]];
    [cell.contentView addSubview:lbl];
   
    lbl = [[UILabel alloc] initWithFrame:CGRectMake(5.0, 20.0, 228.0, 20.0)];
    lbl.font=[UIFont systemFontOfSize:10.0];
    lbl.textAlignment = UITextAlignmentLeft;
    lbl.textColor = [UIColor colorWithRed:57.0/255.0 green:122.0/255.0 blue:159.0/255.0 alpha:1.0];
    lbl.backgroundColor = [UIColor clearColor];
    lbl.highlightedTextColor = [UIColor whiteColor];
    lbl.text =[NSString stringWithFormat:@"%@, %@", [[ArrPOList objectAtIndex:indexPath.row] objectAtIndex:0],[[ArrPOList objectAtIndex:indexPath.row] objectAtIndex:3]];
    [cell.contentView addSubview:lbl];
   
    lbl = [[UILabel alloc] initWithFrame:CGRectMake(230.0, 20.0, 60.0, 20.0)];
    lbl.font=[UIFont systemFontOfSize:10.0];
    lbl.textAlignment = UITextAlignmentRight;
    lbl.textColor = [UIColor grayColor];
    lbl.backgroundColor = [UIColor clearColor];
    lbl.highlightedTextColor = [UIColor whiteColor];
    //lbl.text =[NSString stringWithFormat:@"%@", [[ArrPOList objectAtIndex:indexPath.row] objectAtIndex:0]];
    [cell.contentView addSubview:lbl];
   
    NSArray *Arr1 = [[[ArrPOList objectAtIndex:indexPath.row] objectAtIndex:6] componentsSeparatedByString:@"-"];
    lbl.text = [NSString stringWithFormat:@"%@/%@/%@",[Arr1 objectAtIndex:2],[Arr1 objectAtIndex:1],[Arr1 objectAtIndex:0]];
   
    cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
    cell.backgroundColor=[UIColor clearColor];
    return cell;
}

No comments:

Post a Comment