UISegmentedControl with UITableVIew NSRangeException

Posted by Vivas on Stack Overflow See other posts from Stack Overflow or by Vivas
Published on 2010-03-23T21:12:10Z Indexed on 2010/03/23 21:33 UTC
Read the original article Hit count: 814

Hi,

I am using one UIViewController as shown:

@interface RssViewController : UIViewController <UITableViewDataSource,UITableViewDelegate,BlogRssParserDelegate>

I am displaying an RSS feed in the UITableView (in RssViewController) depending on the segment selected on the UISegmentedControl.

My app crashes when I scroll the tableview then select another segment of the UISegmentedControl. For example I have two RSS feeds by default I am displaying the RSS feed at segment 0. This feed has 36 rows. The RSS feed that I load at segment 1 has only 5 rows. When I scroll the RSS feed at segment 0 THEN before the scrolling stops I switch to the RSS feed at segment 1 I crash the app with the following error:

* Terminating app due to uncaught exception 'NSRangeException', reason: '* -[NSCFArray objectAtIndex:]: index (36) beyond bounds (0)'

If I wait till the scrolling on the RSS feed at segment 0 stops THEN select segment 1, everything works fine.

How can I stop this crashing? I wanted to reuse the same tableview because only the data changes. I can see that it is crashing because of the row count - I went from 36 rows down to 5 rows BUT how can I fix this?

Any help / suggestions would be appreciated.

© Stack Overflow or respective owner

Related posts about iphone

Related posts about rss