iphone - 两个 UIScrollViews 得到 [__NSCFConstantString _isDecompressing] 错误

标签 iphone ios objective-c uiscrollview

首先,抱歉问题的长度。但我一直在寻找答案。我在一个包含两个 UIScrollView 的选项卡式应用程序中创建了一个 View 。我称它们为 topScrollView 和 bottomScrollView。这是.h。

@property (weak, nonatomic) IBOutlet UIScrollView *topScrollView;
@property (weak, nonatomic) IBOutlet UIScrollView *bottomScrollView;

socket 都接线正确。当我开始时,我只是先制作了顶部 ScrollView 。 ScrollView 充满了图片。一切都很好,它在分页时滚动很好,我放了一些在滚动时也会改变的标签。这是保存来自我的 viewDidLoad 方法的图像的数组。
_golfShirtArray = [NSArray arrayWithObjects:
                   [UIImage imageNamed:@"GT018B-RSB-5961.jpg"],
                   [UIImage imageNamed:@"GT042-HDT-7234.jpg"],
                   [UIImage imageNamed:@"gt063-rst-7294.jpg"],
                   [UIImage imageNamed:@"GT045-CBT3-7203.jpg"],
                   [UIImage imageNamed:@"GT018-SDT-5971.jpg"],
                   nil];

然后我在 viewWillAppear 中设置 contentSize,然后调用 loadVisiblePages 方法。我遵循了 Ray Wenderlich 对 ScrollView 的看法。这是我的版本,对不起所有的长代码。
- (void)loadVisiblePages
{
CGFloat pageWidth = 528.0f;
NSInteger page = (NSInteger)floor((_topScrollView.contentOffset.x * 2.0f + pageWidth) / (pageWidth * 2.0f));

_topPageControl.currentPage = page;

NSInteger firstPage = page - 1;
NSInteger lastPage = page + 1;

for (NSInteger i = 0; i < firstPage; i++)
{
    [self purgePage:i];
}

for (NSInteger i = firstPage; i <= lastPage; i++)
{
    [self loadPage:i];
}

for (NSInteger i = lastPage+1; i < _showablePictureArray.count; i++)
{
    [self purgePage:i];
}
}

- (void)loadPage:(NSInteger)page
{
if (page < 0 || page >= _showablePictureArray.count)
{
    return;
}

UIView *pageView = [_pageViews objectAtIndex:page];
if ((NSNull *)pageView == [NSNull null])
{
    CGRect frame = CGRectMake(120, 93, 528, 380); //_topScrollView.bounds;

    //NSLog(@"scrollviewbounds is %@", NSStringFromCGRect(frame));

    frame.origin.x = frame.size.width * page;
    frame.origin.y = 0.0f;

    UIImageView *newPageView = [[UIImageView alloc] initWithImage:[_showablePictureArray objectAtIndex:page]];
    newPageView.contentMode = UIViewContentModeScaleAspectFit;
    newPageView.frame = frame;

    [_topScrollView addSubview:newPageView];
    [_pageViews replaceObjectAtIndex:page withObject:newPageView];

    CGFloat y = 0.0;
    for (NSInteger i = 0; i < _showablePictureArray.count; i++)
    {
        UILabel *descriptionLabel = [[UILabel alloc] initWithFrame:CGRectMake(y, 0, 200.0, 20.0)];

        UILabel *priceLabel = [[UILabel alloc] initWithFrame:CGRectMake(y, 23.0, 200.0, 20.0)];

        NSString *text1 = [_showableDescriptionArray objectAtIndex:i];
        NSString *text2 = [_showablePriceArray objectAtIndex:i];

        [descriptionLabel setText:text1];
        [priceLabel setText:text2];

        descriptionLabel.layer.borderWidth = 2.0f;
        descriptionLabel.layer.borderColor = [UIColor lightGrayColor].CGColor;
        descriptionLabel.layer.cornerRadius = 6.0f;

        priceLabel.layer.borderWidth = 2.0f;
        priceLabel.layer.borderColor = [UIColor lightGrayColor].CGColor;
        priceLabel.layer.cornerRadius = 6.0f;

        [_topScrollView addSubview:descriptionLabel];
        [_topScrollView addSubview:priceLabel];
        y = y + 528;
    }
}
}

- (void)purgePage:(NSInteger)page
{
if (page < 0 || page >= _showablePictureArray.count)
{
    return;
}

UIView *pageView = [_pageViews objectAtIndex:page];
if ((NSNull *)pageView != [NSNull null])
{
    [pageView removeFromSuperview];
    [_pageViews replaceObjectAtIndex:page withObject:[NSNull null]];
}
}

我制作的所有数组都已转移到 _showable... 因为我可以更改用户查看的内容。正如我所说,一切都很好。直到我添加了底部 ScrollView 。我使用了所有相同的代码,但在每个变量和方法之后都有底部。我还调用了 loadVisiblePagesBottom 和 loadVisiblePages。
- (void)loadVisiblePagesBottom
{
CGFloat pageWidthBottom = 528.0f;
NSInteger pageBottom = (NSInteger)floor((_bottomScrollView.contentOffset.x * 2.0f + pageWidthBottom) / (pageWidthBottom * 2.0f));

NSLog(@"page bottom is %ld", (long)pageBottom);

_bottomPageControl.currentPage = pageBottom;

NSInteger firstPageBottom = pageBottom -1;
NSInteger lastPageBottom = pageBottom +1;

for (NSInteger i = 0; i < firstPageBottom; i++)
{
    [self purgePageBottom:i];
}

for (NSInteger i = firstPageBottom; i <= lastPageBottom; i++)
{
    [self loadPageBottom:i];
}

for (NSInteger i = lastPageBottom + 1; i < _showablePictureArrayBottom.count; i++)
{
    [self purgePageBottom:i];
}
}

- (void)loadPageBottom:(NSInteger)pageBottom
{
NSLog(@"page bottom 2 is %ld", (long)pageBottom);
if (pageBottom < 0 || pageBottom >= _showablePictureArrayBottom.count)
{
    return;
}

UIView *pageViewBottom = [_pageViewsBottom objectAtIndex:pageBottom];
if ((NSNull *)pageViewBottom == [NSNull null])
{
    CGRect frameBottom = CGRectMake(120, 482, 528, 380);
    frameBottom.origin.x = frameBottom.size.width * pageBottom;
    frameBottom.origin.y = 0.0f;

    UIImageView *bottomView = [[UIImageView alloc] initWithImage:[_showablePictureArrayBottom objectAtIndex:pageBottom]];
    //UIImageView *bottomView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"GB007-SPD-5918.jpg"]];
    bottomView.contentMode = UIViewContentModeScaleAspectFit;
    bottomView.frame = frameBottom;
    [_bottomScrollView addSubview:bottomView];

    [_pageViewsBottom replaceObjectAtIndex:pageBottom withObject:bottomView];
}
}

- (void)purgePageBottom:(NSInteger)pageBottom
{
if (pageBottom < 0 || pageBottom >= _showablePictureArrayBottom.count)
{
    return;
}

UIView *pageViewBottom = [_pageViewsBottom objectAtIndex:pageBottom];
if ((NSNull *)pageViewBottom != [NSNull null])
{
    [pageViewBottom removeFromSuperview];
    [_pageViewsBottom replaceObjectAtIndex:pageBottom withObject:[NSNull null]];
}
}

我只是还没有贴标签。底部图像数组的创建是。
_golfShortsArray = [NSArray arrayWithObjects:
                    [UIImage imageNamed:@"GB005-nvy-7235.jpg"],
                    [UIImage imageNamed:@"GB005-RSB-7297.jpg"],
                    [UIImage imageNamed:@"gb007-bgm-7320.jpg"],
                    [UIImage imageNamed:@"GB007-NVY-5916.jpg"],
                    [UIImage imageNamed:@"GB007-SPD-5918.jpg"],
                    nil];

这与我对顶部 ScrollView 所做的相同。但是,应用程序因上述错误而崩溃。我做了一些研究,它说我正在尝试解压缩实际上是一个字符串的图像,但数组是相同的,所有图像。我什至跑了 NSZombies,它给了我同样的错误。
[__NSCFConstantString _isDecompressing]: unrecognized selector sent to instance 0x72668

我使用了 bt 并得到了以下内容。
* thread #1: tid = 0x2503, 0x3ad79498 libc++abi.dylib`__cxa_throw, stop reason = breakpoint 1.2
    frame #0: 0x3ad79498 libc++abi.dylib`__cxa_throw
    frame #1: 0x3b32b9be libobjc.A.dylib`objc_exception_throw + 94
    frame #2: 0x33498e06 CoreFoundation`-[NSObject(NSObject) doesNotRecognizeSelector:] + 170
    frame #3: 0x33497530 CoreFoundation`___forwarding___ + 392
    frame #4: 0x333eef68 CoreFoundation`__forwarding_prep_0___ + 24
    frame #5: 0x352f966a UIKit`-[UIImageView initWithImage:] + 66
    frame #6: 0x0006d9d4 JoFitTest`-[SecondViewController loadPageBottom:](self=0x1e575840, _cmd=0x0006f25e, pageBottom=0) + 456 at SecondViewController.m:358
    frame #7: 0x0006d788 JoFitTest`-[SecondViewController loadVisiblePagesBottom](self=0x1e575840, _cmd=0x0006f236) + 388 at SecondViewController.m:334
    frame #8: 0x0006d238 JoFitTest`-[SecondViewController scrollViewDidScroll:](self=0x1e575840, _cmd=0x357119e4, scrollView=0x1e5a5c50) + 164 at SecondViewController.m:286
    frame #9: 0x352bf83a UIKit`-[UIScrollView setContentOffset:] + 618
    frame #10: 0x353da138 UIKit`-[UIScrollView _updatePanGesture] + 2456
    frame #11: 0x353bad88 UIKit`_UIGestureRecognizerSendActions + 128
    frame #12: 0x353bad88 UIKit`_UIGestureRecognizerSendActions + 128
    frame #13: 0x353823f4 UIKit`-[UIGestureRecognizer _updateGestureWithEvent:] + 392
    frame #14: 0x3556fa38 UIKit`___UIGestureRecognizerUpdate_block_invoke_0543 + 48
    frame #15: 0x352a682e UIKit`_UIGestureRecognizerRemoveObjectsFromArrayAndApplyBlocks + 218
    frame #16: 0x352a5292 UIKit`_UIGestureRecognizerUpdate + 1274
    frame #17: 0x352b01e6 UIKit`-[UIWindow _sendGesturesForEvent:] + 766
    frame #18: 0x352afdb2 UIKit`-[UIWindow sendEvent:] + 90
    frame #19: 0x3529d800 UIKit`-[UIApplication sendEvent:] + 380
    frame #20: 0x3529d11a UIKit`_UIApplicationHandleEvent + 6154
    frame #21: 0x36f915a2 GraphicsServices`_PurpleEventCallback + 590
    frame #22: 0x36f911d2 GraphicsServices`PurpleEventCallback + 34
    frame #23: 0x3346a172 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 34
    frame #24: 0x3346a116 CoreFoundation`__CFRunLoopDoSource1 + 138
    frame #25: 0x33468f98 CoreFoundation`__CFRunLoopRun + 1384
    frame #26: 0x333dbebc CoreFoundation`CFRunLoopRunSpecific + 356
    frame #27: 0x333dbd48 CoreFoundation`CFRunLoopRunInMode + 104
    frame #28: 0x36f902ea GraphicsServices`GSEventRunModal + 74
    frame #29: 0x352f1300 UIKit`UIApplicationMain + 1120
    frame #30: 0x0006a034 JoFitTest`main(argc=1, argv=0x2fd98d00) + 116 at main.m:16
    frame #31: 0x3b762b20 libdyld.dylib`start + 4

我真的不知道这一切意味着什么。我只是不明白我哪里出错了。它如何适用于顶部而不是底部。所有的变量都是不同的,所以我看不到如何使用已释放对象的内存。任何帮助将不胜感激。我不知道从这里去哪里。感谢检查出来。另外,这里是 scrollViewDidScroll 方法。
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
if (scrollView == _topScrollView)
{
    [self loadVisiblePages];
}else if (scrollView == _bottomScrollView)
{
    NSLog(@"Bottom Scroll");
    [self loadVisiblePagesBottom];
}
}

再次感谢。

最佳答案

问题是 _showablePictureArrayBottom 中包含字符串而不是图像。

我可以从错误消息中看出这一点:

[__NSCFConstantString _isDecompressing]: unrecognized selector sent to instance 0x72668

第一部分是告诉你传递消息的类。 __NSCFConstantString是与 NSString 相关的类簇之一.当您为变量分配了错误的类型,或者您有一个过早的释放时,您将得到这个。

关于iphone - 两个 UIScrollViews 得到 [__NSCFConstantString _isDecompressing] 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18532658/

相关文章:

iphone - 如何检查本地 wifi 连接

iphone - 没有透明部分的图像蒙版

ios - 将 UIWebView 转换为 PDF/Image 仅提供一英寸宽的输出

iphone - UIImagePicker 和 AVCaptureSession 同时访问相机

iphone - UITableView数据在滚动时多次显示

ios - 将字体大小缩放到标签 iOS Swift 的宽度

c++ - 我可以将一个库作为静态库并在 iOS 项目中编译吗?

ios - 我如何在 ios 中使用 parse 执行 PFRelation 查询

iphone - UIView 动画中的 setFrame 不移动,只捕捉到位

objective-c - 带有尾随闭包的 Swift 到 Objective-C 调用调用了错误的方法