Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.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 阿拉斯套图像问题_Iphone_Xcode - Fatal编程技术网

Iphone 阿拉斯套图像问题

Iphone 阿拉斯套图像问题,iphone,xcode,Iphone,Xcode,我的代码分为两部分: 第一个是我的表视图的“cellforrowatinexpath”方法。在这个表视图中,我应该在每个单元格中显示3个按钮,每个按钮都是不同的图像。图像位于名为“Photosaray”的NSMutableArray中。看起来像这样 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *

我的代码分为两部分:

第一个是我的表视图的“cellforrowatinexpath”方法。在这个表视图中,我应该在每个单元格中显示3个按钮,每个按钮都是不同的图像。图像位于名为“Photosaray”的NSMutableArray中。看起来像这样

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

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    if (photosArray.count > 0) {
        for (int i = 0; i < 3; i++) {
            if (photosArray.count > photoCounter) {

                //position the UiButtons in the scrollView
                CGRect frame = CGRectMake((i*100) + 30, 5, 60, 60);

                //Create the UIbuttons
                UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
                [button setTag:i];
                [button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
                button.frame = frame;
                button.layer.borderWidth = 2;
                button.layer.cornerRadius = 5;
                button.clipsToBounds = YES;

                //Add images to the button

                NSLog(@"PhotosArray count is: %d",photosArray.count);
                if ([[photosArray objectAtIndex:0] isKindOfClass:[UIImage class]]) {
                    NSLog(@"UIImage class true");
                }
                if ([[photosArray objectAtIndex:0] isMemberOfClass:[UIImage class]]) {
                    NSLog(@"UIImage class true");
                }


                UIImage *btnImg = [self.photosArray objectAtIndex:photoCounter];
                //UIImage *btnImg2 = [UIImage imageNamed:@"GameOver"];
                photoCounter++;

                [button setBackgroundImage:btnImg forState:UIControlStateNormal];

                [cell.contentView addSubview:button];
            }
        }
    }else{
        UILabel *noImages = [[UILabel alloc] initWithFrame:CGRectMake(0, 25, 320, 20)];
        noImages.text = @"No images";
        noImages.textAlignment = NSTextAlignmentCenter;
        [cell.contentView addSubview:noImages];
    }

    return cell;
}
现在,对于这个问题,创建的按钮中没有图像。我只得到一个有边框和圆角的透明按钮


为什么会这样?

最近我注意到,我在自述中遗漏了一个重要的部分(现在已经更新)

如果要访问
dismissViewControllerAnimated:completion:
completion块中的ALAsset对象,则必须保持WSAssetPickerController的强引用

如果在调用
dismissViewControllerAnimated:completion:
之前未持有对选择器控制器的强引用,则在执行完成块之前将释放选择器控制器,从而生成AlassetPicker库(在WSAssetPicker代码中内部使用)在尝试访问
assetPickerController:didFinishPickingMediaWithAssets:
委托方法中传递的
assets
数组中的数据集之前释放

如果AlassetLibrary被释放,AlassetLibrary拥有的ALAssets将过期,对
asset.defaultRepresentation.fullScreenImage
的调用将返回null

以下内容将在关闭选择器控制器视图时保留库:

- (void)assetPickerController:(WSAssetPickerController *)sender didFinishPickingMediaWithAssets:(NSArray *)assets
{
    // Hang on to the picker to avoid ALAssetsLibrary from being released.
    self.picker = sender;

    __block id weakSelf = self; 
    // Note: Instead of `id` you could specify the class of `self` order to access properties with dot notation.

    // Dismiss the WSAssetPickerController.
    [self dismissViewControllerAnimated:YES completion:^{

        // Do something with the assets here.


        // Release the picker.
        [weakSelf setPicker:nil];
    }];
}

另一种方法是在调用dismissViewControllerAnimated:completion:之前处理ALASSET数组,但这可能会导致选择器控制器的解雇延迟,从而导致用户体验不佳。

最近我注意到,我在自述文件(现在已更新)中遗漏了一个重要部分

如果要访问
dismissViewControllerAnimated:completion:
completion块中的ALAsset对象,则必须保持WSAssetPickerController的强引用

如果在调用
dismissViewControllerAnimated:completion:
之前未持有对选择器控制器的强引用,则在执行完成块之前将释放选择器控制器,从而生成AlassetPicker库(在WSAssetPicker代码中内部使用)在尝试访问
assetPickerController:didFinishPickingMediaWithAssets:
委托方法中传递的
assets
数组中的数据集之前释放

如果AlassetLibrary被释放,AlassetLibrary拥有的ALAssets将过期,对
asset.defaultRepresentation.fullScreenImage
的调用将返回null

以下内容将在关闭选择器控制器视图时保留库:

- (void)assetPickerController:(WSAssetPickerController *)sender didFinishPickingMediaWithAssets:(NSArray *)assets
{
    // Hang on to the picker to avoid ALAssetsLibrary from being released.
    self.picker = sender;

    __block id weakSelf = self; 
    // Note: Instead of `id` you could specify the class of `self` order to access properties with dot notation.

    // Dismiss the WSAssetPickerController.
    [self dismissViewControllerAnimated:YES completion:^{

        // Do something with the assets here.


        // Release the picker.
        [weakSelf setPicker:nil];
    }];
}

另一种方法是在调用
dismissViewControllerAnimated:completion:
之前处理ALASSET数组,但这可能会导致拾取控制器的解雇延迟,从而导致用户体验不佳。

UITableView将多次调用您的cellForRowAtIndex:,所以有一个柜台似乎不是个好主意。您只需获取相应索引路径的图像。此外,在使用模拟器时,尝试将这些图像写入磁盘,并使用Finder手动查看它们的外观,可能您从资产库检索的图像实际上是空的,问题就在那里。UITableView将多次调用您的CellForRowatinex(每次滚动等),所以有一个柜台似乎不是个好主意。您只需获取相应索引路径的图像。此外,在使用模拟器时,尝试将这些图像写入磁盘,并使用Finder手动查看它们的外观,可能您从资产库检索的图像实际上是空的,问题就在那里。@property(非原子,强)WSAssetPickerController*picker;唯一的问题是weakSelf.picker没有被识别,并且说:“在类型为'\u strong id'的对象上找不到属性'picker',我该如何处理它?”?对不起我的无知,我对blocksOops很陌生,我的错误。在您的示例中,我不知道
self
的类别,因此我制作了
weakSelf
一个
id
。您可以指定
self
的类,以便使用点符号访问
picker
属性,也可以在
weakSelf
上调用
setPicker:
。我编辑了我的答案。@property(非原子,强)WSAssetPickerController*picker;唯一的问题是weakSelf.picker没有被识别,并且说:“在类型为'\u strong id'的对象上找不到属性'picker',我该如何处理它?”?对不起我的无知,我对blocksOops很陌生,我的错误。在您的示例中,我不知道
self
的类别,因此我制作了
weakSelf
一个
id
。您可以指定
self
的类,以便使用点符号访问
picker
属性,也可以在
weakSelf
上调用
setPicker:
。我编辑了我的答案。