Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/42.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/118.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 当我同时使用自定义表格视图单元格时,如何通过NSArray设置表格视图的文本?_Iphone_Ios_Xcode_Uitableview_Ios4 - Fatal编程技术网

Iphone 当我同时使用自定义表格视图单元格时,如何通过NSArray设置表格视图的文本?

Iphone 当我同时使用自定义表格视图单元格时,如何通过NSArray设置表格视图的文本?,iphone,ios,xcode,uitableview,ios4,Iphone,Ios,Xcode,Uitableview,Ios4,我有一个通过自定义表格视图单元格设计的UITable视图。我希望每个单元格上的文本都不一样,所以我在CustomCell中添加了一个标签,并在其上连接了一个IBOutlet,但我很难理解代码的逻辑部分,如果有任何帮助,我将不胜感激。到目前为止,我有: //这是在我的表视图控制器类中 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

我有一个通过自定义表格视图单元格设计的UITable视图。我希望每个单元格上的文本都不一样,所以我在CustomCell中添加了一个
标签
,并在其上连接了一个
IBOutlet
,但我很难理解代码的逻辑部分,如果有任何帮助,我将不胜感激。到目前为止,我有:

//这是在我的表视图控制器类中

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

    if (cell == nil) {
        NSArray *object = [[NSBundle mainBundle]loadNibNamed:@"TableOfContentsCell" owner:self options:nil];

        for (id currentObject in object) {
            if ([currentObject isKindOfClass:[UITableViewCell class]]) {

            cell = (TableOfContentsCell *)currentObject;
            break;
            }
        }

    }

    //cell.textLabel.textColor = [UIColor whiteColor];

    // Configure the cell...

    return cell;
}


//This is in my Custom Table View Cell Class.

-(void)setTableText{
cellLabel.text = [table.tableCellText objectAtIndex:0];
}

当我想要的文本在数组中时,我不知道如何设置文本!提前谢谢

只需从tableView:cellForRowAtIndexPath填充它即可

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    ...
    // Configure the cell...
    cellLabel.text = [table.tableCellText objectAtIndex:indexPath.row];
    return cell;
}

只需确保tableview可以访问table.tableCellText。

不需要单独的方法。在qn中的代码中有两行注释…(//配置单元格…) 将此代码添加到tht部分

假设在自定义单元格中有两个标签 然后向它们添加标记(这里是1和2),并通过viewwithtag:method在代码中获取其引用

UILabel *label=(UILabel *)[cell viewWithTag:1];
[label setText:@"2"];

UILabel *label2=(UILabel *)[cell viewWithTag:2];
[label2 setText:@"sasd"];
您必须保持的条件是,单元格的内容必须被唯一地标记,并且使用此方法可以获取自定义单元格中任何视图的引用


快乐编码

根据需要创建自定义单元格类。那么

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

 TableCustomCell *cell = (TableCustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

//.....................

cell.yourLabel.text = [yourArray objectAtIndex:indexPath.row];

return cell;
}

我不清楚您为什么要将数据加载到自定义单元格的标签中,请澄清。 其次,在“注释配置”单元格下方,您可以自定义单元格。正如您设置textColor所做的那样。 只需在表视图控制器类中声明该数组

并在下面编写代码

    // Configure the cell...

    cell.cellLabel.text = [yourArrayName objectAtIndex:indexPath.row];

希望能有所帮助。

您可以像这样声明方法:-(void)setTableText:(id)sender,您可以在其中向方法传递一个整数值并调用数组,如:[yourArray objectAtIndex:sender];