两个UIScrollViews收到[__NSCFConstantString _isDecompressing]错误

时间:2013-08-30 12:14:31

标签: iphone ios objective-c uiscrollview

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

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

插座均正确接线。当我开始时,我首先制作了顶部滚动视图。滚动视图中充满了图片。一切都很好,它通过分页滚动得很好,我在滚动时添加了一些标签。这是保存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对卷轴视图的啧啧。这是我的版本,对不起所有长代码。

- (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 ......因为我可以更改用户看到的内容。正如我所说,一切都很好。直到我添加了底部滚动视图。我使用了所有相同的代码,但是在每个变量和方法之后都有底部。我还将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];

这与我在顶部滚动视图中所做的相同。但是,应用程序因所述错误而崩溃。我做了一些研究,它说我试图解压缩一个实际上是字符串的图像,但数组是相同的,所有图像。我甚至跑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];
}
}

再次感谢。

1 个答案:

答案 0 :(得分:3)

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

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

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

第一部分告诉你正在传递消息的类。 __NSCFConstantString是与NSString关联的类的集群之一。当你为变量分配了错误的类型,或者你有一个过早的释放时,你会得到这个。