简体   繁体   中英

iOS 6 UIScrollview: Help My Taco App Keeps Crashing

I have a UIScrollView full of tacos. I attached a pull-to-refresh handler to it via: https://github.com/samvermette/SVPullToRefresh

It extends uiscrollview, and exposes this method:

[scrollview addInfiniteScrollingWithActionHandler:^{
    // Get me more tacos
}];

When InfiniteScrolling is triggered, I clear the scrollview's subviews and data array(intentionally) and replace it with a new set. It works great the first time. However, when I want to load more tacos it crashes.

I get:

-[SVInfiniteScrollingView retain]: message sent to deallocated instance 0x1e5db5d0

Not surprisingly, if I leave 1 subview left in my UIScrollview, everything works fine.

Question: How can I fix this?

I thought about declaring my properties with a strong pointer, like:

@property (strong, nonatomic) IBOutlet tacoScroller *tacoScroller;

But , I worry about a retain cycle & it also doesn't work.

Any help would be appreciated, perhaps I'm missing something fundamental.

Edit: I'm using ARC

Use an UITableView to show your tacos, this way you will reuse views and avoid wasting memory. Also it is the easiest and most convenient way to show a list of things.

根据您的描述,最简单的解决方案是在滚动视图内添加一个空的和隐藏的子视图,我敢肯定它不会占用大量内存。

I think you are invoking the wrong method. Infinite scrolling is for other purposes.

You probably want to use

[scrollView addPullToRefreshWithActionHandler:^{ ... }];

Also, as others pointed out, you definitely should consider to use a UITableView to present your data, which seems to be very suitable for the task.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM