Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone ech行UITableView中的不同数据_Iphone_Uitableview - Fatal编程技术网

Iphone ech行UITableView中的不同数据

Iphone ech行UITableView中的不同数据,iphone,uitableview,Iphone,Uitableview,我想知道如何在表格的每个单元格中显示不同的数据 在我的例子中,我有一个uitable,它有4行。我想在第一行显示姓名、第二行地址、第三行电话号码、第四行电子邮件。有什么建议吗 谢谢…当您实现tableView:cellforrowatinexpath:方法时,您可以在indexath.row值上设置一个条件。这是假设您对数据的每一行使用相同的视图类型 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndex

我想知道如何在表格的每个单元格中显示不同的数据

在我的例子中,我有一个uitable,它有4行。我想在第一行显示姓名、第二行地址、第三行电话号码、第四行电子邮件。有什么建议吗


谢谢…

当您实现
tableView:cellforrowatinexpath:
方法时,您可以在
indexath.row
值上设置一个条件。这是假设您对数据的每一行使用相同的视图类型

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
    }
        switch (indexPath.row) {
        case 0:
            cell.textLabel.text = /*  you data goes here */;
            break;
        case 1:
            cell.textLabel.text = /*  you data goes here */;
            break;
        /* your additional cases go here */
        }
    return cell;    
}

如果要为每一行使用不同的表视图单元格类型,则必须为每一行使用不同的单元格标识符,并使用
switch
语句用所需的特定单元格类型实例化
UITableViewCell
,或者一个
if
语句。

当您实现
tableView:cellforrowatinexpath:
方法时,您可以在
indexPath.row
值上设置一个条件。这是假设您对数据的每一行使用相同的视图类型

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
    }
        switch (indexPath.row) {
        case 0:
            cell.textLabel.text = /*  you data goes here */;
            break;
        case 1:
            cell.textLabel.text = /*  you data goes here */;
            break;
        /* your additional cases go here */
        }
    return cell;    
}

如果要为每一行使用不同的表视图单元格类型,则必须为每一行使用不同的单元格标识符,并使用
switch
语句或
If
语句使用所需的特定单元格类型实例化
UITableViewCell

将数据存储在数组中
在CellForRowatineXpath方法中写入-->cell.textable.text=[arr objectAtIndex:indexath.row]

将ur数据存储在数组中
在CellForRowatineXpath方法中写入-->cell.textable.text=[arr objectAtIndex:indexath.row]

在本例中,我假设您没有将数据存储在数组中。使用数组很容易,可以执行cell.textlab.text=[array objectAtIndex:indexath.row];在本例中,我假设您没有将数据存储在数组中。使用数组很容易,可以执行cell.textlab.text=[array objectAtIndex:indexath.row];