Search code examples
iphoneiosios5uitableview

how to add 5 different custom cells in tableView


I want to show different data from web in my tableview but I am not getting how to show them in separate cells in one section of a table can any one help me to show in one cell

cell.textLabel.text=app.i_name;

in second cell

cell.textLabel.text=app.i_phone;

in third cell

cell.textLabel.text=app.i_hours;

in forth cell

cell.textLabel.text=app.i_address;

in fifth cell

cell.textLabel.text=app.i_email;

my cell for row at index is as

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    static NSString *CellIdentifier = @"Single Cell";
    SingleCell *cell =(SingleCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];


    if (cell == nil) {
        UIViewController *c = [[UIViewController alloc] initWithNibName:@"SingleCell" bundle:nil];
        cell = (SingleCell *) c.view;
        //[c release];

    }
appDC * application = [dataArray objectAtIndex:[indexPath row]];

        //cell.namelbl.text=application.application_name;


return cell;
}

Solution

  • Try this code :

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
    
        static NSString *CellIdentifier = @"Single Cell";
        SingleCell *cell =(SingleCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
    
        if (cell == nil) {
            UIViewController *c = [[UIViewController alloc] initWithNibName:@"SingleCell" bundle:nil];
            cell = (SingleCell *) c.view;
            //[c release];
    
        }
        appDC * application = [dataArray objectAtIndex:[indexPath row]];
    
        //cell.namelbl.text=application.application_name;
        if (indexPath.row == 0)
        {
            cell.textLabel.text=application.i_name;
        }
        else if (indexPath.row == 1)
        {
            cell.textLabel.text = application.i_iphone;
        }
        else if (indexPath.row == 2)
        {
            cell.textLabel.text = application.i_hours;
        }
        else if (indexPath.row == 3)
        {
            cell.textLabel.text = application.i_address;
        }
        else
        {
            cell.textLabel.text = application.i_email;
        }
    
    
    
        return cell;
    }
    

    Hope this answer will help. Cheers