Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/104.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 UIImageView仅在选中UITableViewCell时显示_Ios_Ipad_Uitableview_Uiimageview - Fatal编程技术网

Ios UIImageView仅在选中UITableViewCell时显示

Ios UIImageView仅在选中UITableViewCell时显示,ios,ipad,uitableview,uiimageview,Ios,Ipad,Uitableview,Uiimageview,我创建了一个自定义UITableViewCell,并向其中添加了13个UIImageView。在我的cellForRowAtIndexPath方法中,我为每个图像视图设置图像(如果有可用的照片),但是当视图加载时,没有任何表单元格显示其中的照片。但是,当我选择一个单元格时,所有图像都会加载。然后,当我选择另一个单元格时,上一个单元格中的图像将消失,而我刚才选择的单元格的图像将显示出来。下面是我的cellForRowIndexPath方法: - (UITableViewCell *)tableVi

我创建了一个自定义UITableViewCell,并向其中添加了13个UIImageView。在我的cellForRowAtIndexPath方法中,我为每个图像视图设置图像(如果有可用的照片),但是当视图加载时,没有任何表单元格显示其中的照片。但是,当我选择一个单元格时,所有图像都会加载。然后,当我选择另一个单元格时,上一个单元格中的图像将消失,而我刚才选择的单元格的图像将显示出来。下面是我的cellForRowIndexPath方法:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *tableCell = [self.tableView dequeueReusableCellWithIdentifier:@"photoSessionCell"];
    PhotoSessionCell * cell = (PhotoSessionCell*) tableCell;
    NSMutableArray *photos = [[self dataSource] objectAtIndex:[indexPath indexAtPosition:1]]; 

    for (int i = 0; i < 13; i++) {
        if (i < [photos count]) {
            UIImage * currImage = [photos objectAtIndex:i];
            switch (i) {
                case 0:
                    [[cell image1] setImage:currImage];
                    break;
                case 1:
                    [[cell image2] setImage:currImage];
                    break;
                case 2:
                    [[cell image3] setImage:currImage];
                    break;
                case 3:
                    [[cell image4] setImage:currImage];
                    break;
                case 4:
                    [[cell image5] setImage:currImage];
                    break;
                case 5:
                    [[cell image6] setImage:currImage];
                    break;
                case 6:
                    [[cell image7] setImage:currImage];
                    break;
                case 7:
                    [[cell image8] setImage:currImage];
                    break;
                case 8:
                    [[cell image9] setImage:currImage];
                    break;
                case 9:
                    [[cell image10] setImage:currImage];
                    break;
                case 10:
                    [[cell image11] setImage:currImage];
                    break;
                case 11:
                    [[cell image12] setImage:currImage];
                    break;
                default:
                    [[cell image13] setImage:currImage];
                    break;
            }
        } else {
            break;
        }
    }

    NSDate* date = [[self dates] objectAtIndex:[indexPath indexAtPosition:0]];
    NSDateFormatter * format  = [[NSDateFormatter alloc] init];
    [format setDateStyle:NSDateFormatterLongStyle];
    [[cell textLabel] setText:[format stringFromDate:date]];

    return cell;
}
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
UITableViewCell*tableCell=[self.tableView dequeueReusableCellWithIdentifier:@“photoSessionCell”];
PhotoSessionCell*单元格=(PhotoSessionCell*)表格单元格;
NSMutableArray*photos=[[self dataSource]objectAtIndex:[indexPath indexaposition:1]];
对于(int i=0;i<13;i++){
如果(我<[照片计数]){
UIImage*currImage=[照片对象索引:i];
开关(一){
案例0:
[[cell image1]setImage:currImage];
打破
案例1:
[[cell image2]setImage:currImage];
打破
案例2:
[[cell image3]setImage:currImage];
打破
案例3:
[[cell image4]设置图像:currImage];
打破
案例4:
[[cell image5]setImage:currImage];
打破
案例5:
[[cell image6]设置图像:currImage];
打破
案例6:
[[cell image7]setImage:currImage];
打破
案例7:
[[cell image8]setImage:currImage];
打破
案例8:
[[cell image9]setImage:currImage];
打破
案例9:
[[cell image10]setImage:currImage];
打破
案例10:
[[cell image11]setImage:currImage];
打破
案例11:
[[cell image12]设置图像:currImage];
打破
违约:
[[cell image13]设置图像:currImage];
打破
}
}否则{
打破
}
}
NSDate*date=[[self-dates]objectAtIndex:[indexath-indexaposition:0]];
NSDateFormatter*格式=[[NSDateFormatter alloc]init];
[格式setDateStyle:NSDateFormatterLongStyle];
[[cell textLabel]setText:[format stringFromDate:date]];
返回单元;
}

为什么要执行[cell imageX]设置图像。。。您不想只在“cell”上设置图像,而不担心imageX吗?如果
dequeueReusableCellWithIdentifier
返回nil,您会怎么做?通常,您会尝试退出队列,如果它无法退出队列(例如,因为没有可退出队列),则创建一个单元格。“出列”是一种优化,如果您有可以回收的旧单元(例如,因为它们已滚动出视图),则不会创建新单元,但它不能替代创建单元。创建包含13个ImageView的单元格的代码在哪里?我正在设置特定的图像,因为它会影响定位。如果不设置text,会发生什么?“textLabel”是默认tableview单元格文本标签字段的名称。自定义单元格中的UILabel是否使用相同的名称?我将自己的UILabel放在故事板中的自定义单元格上,并将其链接到自定义单元格类中的UILabel属性,该属性使用不同的名称(在我的示例中为label1),并且工作正常。