如何在tableView中添加5个不同的自定义单元格

Noo*_*oor 7 iphone uitableview ios ios5

我想在我的tableview中显示来自web的不同数据但是我没有得到如何在表的一个部分中的单独单元格中显示它们可以帮助我在一个单元格中显示

cell.textLabel.text=app.i_name;
Run Code Online (Sandbox Code Playgroud)

在第二个细胞中

cell.textLabel.text=app.i_phone;
Run Code Online (Sandbox Code Playgroud)

在第三个细胞中

cell.textLabel.text=app.i_hours;
Run Code Online (Sandbox Code Playgroud)

在第四个细胞中

cell.textLabel.text=app.i_address;
Run Code Online (Sandbox Code Playgroud)

在第五个细胞中

cell.textLabel.text=app.i_email;
Run Code Online (Sandbox Code Playgroud)

我索引行的单元格为

- (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;
}
Run Code Online (Sandbox Code Playgroud)

IKQ*_*IKQ 5

试试这段代码:

- (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;
}
Run Code Online (Sandbox Code Playgroud)

希望这个答案会有所帮助.干杯

  • 我相信提问者试图将数组中每个元素的所有数据都放到一个单元格中......我认为这只给了他第一个单元格的原因是因为他的数组中只有一个元素,当应用程序试图填充表只会给他第一个单元格.肯定需要创建一个自定义单元格来容纳从"dataArray"数组中提取的"应用程序"对象中的所有数据.查看此链接http://stackoverflow.com/questions/4917027/ios-steps-to-创建定制-的UITableViewCell与 - XIB文件 (3认同)