views:

300

answers:

2

I am trying to graph large amounts of data in a UIView as a subview of a UIScrollView. In order to overcome the memory limitations surrounding enormous UIViews, I plan, once the scrollview's offset has reached the maximum or minimum offset, to redraw the view with the new data either with a lesser "x" value if it has reached minimum, or visa versa, and then increase the view's offset to the opposite of its current position (ie MAX-->MIN and MIN-->MAX). I have attempted this with the following code.

- (void)scrollViewDidScroll:(UIScrollView *) scrollViewer {

 CGPoint p = scrollViewer.contentOffset;

 if(p.x==0){
     if(appDel.windownum>0){
         appDel.windownum--;
         [graphview setNeedsDisplay];
     }
 }

 if(p.x==1000){
     if(appDel.pcont>appDel.windownum*100){
         appDel.windownum++;
         [graphview setNeedsDisplay];
     }
 }
}

appDel.windownum is the reference for the graph section the view is currently displaying. If it equals zero, it is displaying the first hundred values. If it is one, the next hundred, etc. Once this variable has been reset in the appDelegate, the graph is redrawn with the new index of values, and the scrolloffset is reset. However, when this code is run, the program crashes. With and error:

TERMINATING_DUE_TO_UNCAUGHT_EXCEPTION

It crashes in the simulator. What have I done wrong?

XCode 3.2.1 iPhone Firmware 3.1.3

A: 

It does crash the simulator. The error produced is: TERMINATING_DUE_TO_UNCAUGHT_EXCEPTION.

James
You should add this additional information to the main body. I'll go ahead and do it for you since I am here. You should always add any addition information in the body of the question. This format is different form a traditional forum.
TechZen
Sorry about that, I had not created a bona-fide account, so I couldn't edit the body...I think. Anyway, the issue has been resoled. I had simply forgotten to synthesize windownum in the appDelegate (duuhhh). Thanks anyway.
James
You should check this answer as the correct one so the system knows the question is answered.
TechZen
A: 

I don't see a problem with your code as presented (need more detail) but I do have a design suggestion for the problem of displaying a large graph.

I have become enamored of late with using tables on the iPhone. You can display anything into a table and they can hold any views. It sounds like you are displaying a large, long graph and you could do this in a table and let the table handle the display for you.

You would need to create a custom UITableViewCell that could display a slice of the chart. It would work just like the view you use now except it would display a fixed range in the chart. (You data model would have to be able to chop the data up into rows/ranges.) Then display the cells with no lines.

This way, the tableview handles drawing only those parts of the chart being immediately displayed. That will help with both memory and responsiveness. From the user's perspective, it will look like a single arbitrarily long scrolling graph.

TechZen
I'll give this a go. Thanks.
James
Okay, a bit of an issue with this solution. My graph will be view in portrait mode, and will scroll left to right. UITableViews, it seems, can only scroll up and down, and are not scalable on the x axis. Given these criteria, could your solution still work?
James
No, but why does it have to be in portrait? It's quite normal for iPhone apps to operate in landscape. Landscape would seem to give your users a wider view of the graph. Even if you go with portrait, you will probably want to implement some kind of view swapping solution that mimics a table going sideways. Mobile platforms just don't have the horsepower to handle large graphics. You have to chop them up.
TechZen
You might want to look at core plot http://code.google.com/p/core-plot/
TechZen