Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/100.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
Ios 试图设置UILabel的文本时,UIImage将消失_Ios_Objective C_Uitableview - Fatal编程技术网

Ios 试图设置UILabel的文本时,UIImage将消失

Ios 试图设置UILabel的文本时,UIImage将消失,ios,objective-c,uitableview,Ios,Objective C,Uitableview,我正在使用以下代码初始化UITableView中的文本标签: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSString *CellIdentifier = [menuItems objectAtIndex:indexPath.row]; UITableViewCell *cell = [tableView deq

我正在使用以下代码初始化UITableView中的文本标签:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *CellIdentifier = [menuItems objectAtIndex:indexPath.row];
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
    [cell.textLabel setText: [menuTitlesEN objectAtIndex:indexPath.row]];
    return cell;
}
我的表格由四个静态单元格组成,每个单元格包含一个UIImageView和一个UILabel

未调用
setText
时,我的表看起来应该是:

但是调用
setText
会导致
UIImage
s不知何故消失:


我对iOS开发非常陌生。有人能给我指引正确的方向吗?

试试这样可能会有帮助

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

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    cell.imageView.image = [UIImage imageNamed:@"Image name that you have"];
    [cell.textLabel setText: [menuTitlesEN objectAtIndex:indexPath.row]];
    return cell;
}

由于您正在覆盖默认单元格(
cell.textLabel
)的
UILabel
,因此非常感谢。因此,最好将标记属性指定给
UITableViewCell
中的自定义
UILabel
,然后为其指定文本

尝试类似的方法:

UILabel *lbl = (UILabel*)[cell viewWithTag:identityOfUILabel];
[lbl setText: [menuTitlesEN objectAtIndex:indexPath.row]];

单元格最终的外观如何与第一张图像中的相同?我有一种感觉,因为在您的源代码中,您定义的NSString
CellIdentifier
的名称以蓝色突出显示,我只能假设它恰好与您在.h文件中为图像图标使用的名称相同。@SantaClaus当我注意到对
setText
的调用时。这是有效的,但您能描述一下有什么不同吗?访问
cell.textlab
是否会处理嵌入单元格中的任何视图,而是创建一个简单的
UILabel
?默认情况下,单元格有一组样式,您可以查看这些样式。默认情况下,
UITableViewCell
在单元格中有一个标题(
UILabel
)和
UIImageView
。如果您尝试使用这些视图,则嵌入的视图将与这些视图重叠。您需要自己创建自定义单元格,或者只需使用默认的UITableViewCell视图