Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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;
}
like image 721
Noor Avatar asked Dec 19 '12 13:12

Noor


People also ask

How do you add space between tableView cells?

The way I achieve adding spacing between cells is to make numberOfSections = "Your array count" and make each section contains only one row. And then define headerView and its height. This works great.

How do I add a prototype cell to UITableView?

Choose iOS -> Source -> Cocoa Touch Class. Name the class TableCiewController and make it a subclass of UITableViewController. Go to the TableViewController. swift file and declare the following array.


2 Answers

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

like image 51
IKQ Avatar answered Oct 27 '22 00:10

IKQ


i solved this question by doing this code thanks for all giving suggestion

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

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


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



     }

    appDC * application = [dataArray objectAtIndex:0];
    if (indexPath.row == 0)
    {
        cell.lblinfo.text=application.i_name;
    }
     if (indexPath.row == 1)
    {
        cell.lblinfo.text = application.i_phone;
    }
     if (indexPath.row == 2)
    {
        cell.lblinfo.text = application.i_hours;
    }
     if (indexPath.row == 3)
    {
        cell.lblinfo.text = application.i_address;
    }
    if (indexPath.row == 4)
    {
        cell.lblinfo.text = application.i_email;
    }



    return cell;
}
like image 28
Noor Avatar answered Oct 27 '22 00:10

Noor