Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

noahgolm

macrumors member
Original poster
Aug 18, 2010
65
0
Okay, so I'm developing my own personal xkcd app (I friggin' love that comic). As some of you may know, the creator made a JSON script with the newest comic for ease of use. I have successfully parsed that and, when I use a UIImageView, can show the semi-daily comic. Because of the change of comic size and lack of maneuverability, however, I wanted to transfer this image to a UIScrollView. I thought it would be as simple as adding the imageView as a subview of the scrollView, but the image never actually shows up when that happens! Here's my code... (I have the IBOutlet and properties declared in the .h file, so that's not the problem)

Code:
UIImageView *tempImageView = [[UIImageView alloc] initWithImage:imager]; // imager is the actual image
	self.imageView = tempImageView;
	[tempImageView release];
	
	scrollView.contentSize = CGSizeMake(imageView.frame.size.width, imageView.frame.size.height);
	scrollView.maximumZoomScale=4.0;
	scrollView.minimumZoomScale=0.75;
	scrollView.clipsToBounds=YES;
	scrollView.delegate=self;
	[scrollView addSubview:imageView];

I tried adding the "tempImageView" directly as a subview as well, but still no results! What could be happening here?
 

noahgolm

macrumors member
Original poster
Aug 18, 2010
65
0
Yes, I added it (as stated earlier)...
Code:
IBOutlet UIScrollView *scrollView;

and then...
Code:
@property(nonatomic,retain)UIScrollView *scrollView;

It's also hooked up to a proper UIScrollView in IB. Any ideas on what's going on here? The setup with JSON and the tempImageView works when just displaying an UIImageView, so it has to be something with the scrollView.
 

noahgolm

macrumors member
Original poster
Aug 18, 2010
65
0
In fact, I'll put up the project, just in case someone wants to look at it. Tis in the attachment!
 

Attachments

  • xkcd.zip
    799.8 KB · Views: 100

noahgolm

macrumors member
Original poster
Aug 18, 2010
65
0
If you look through the .m file, you'll see that the image itself is gathered from a link (as in the image has "dataWithContentsOfURL"). The link is gathered from the JSON. Again, this works with just displaying the UIImageView. Strange!
 

nickculbertson

macrumors regular
Nov 19, 2010
226
0
Nashville, TN
I thumbed around with it a bit but still nothing. I never got the content of the URL to show up. It might just be a simulator thing. Good luck finding your answer!

Nick
 

noahgolm

macrumors member
Original poster
Aug 18, 2010
65
0
Here's a newer version of the project. Same problem!
 

Attachments

  • xkcdApp.zip
    1.1 MB · Views: 82

noahgolm

macrumors member
Original poster
Aug 18, 2010
65
0
The image is not nil. I use the line
Code:
imager = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:imageString]]];

where "imager" is the UIImage, and "imageString" is a string containing the picture's URL ("http://imgs.xkcd.com/comics/wisdom_teeth.png" so far, but changes as the comic updates).

The frame is made with this...
Code:
CGRect frame = CGRectMake(0, 0, imager.size.width, imager.size.height);
	[imageView initWithFrame:frame];
 
Last edited:

PhoneyDeveloper

macrumors 68040
Sep 2, 2008
3,114
93
I downloaded your sample code. Ran it. And I see a cartoon in the Sim.

So what's the problem again?

I turned the scrollview back on and that works too.
 

Attachments

  • xkcdApp.zip
    44.5 KB · Views: 139
Last edited:

noahgolm

macrumors member
Original poster
Aug 18, 2010
65
0
OK, I just ran it off of your attachment, and it actually works. That seems... Weird. I did notice you changed a few lines of code, though. Also, in IB, it looks like you have the UIImageView on top of the UIScrollView. Also, there was no subview of scrollView added. Was the scrolling just used as a way of viewing the entire part of the screen that the image was part of? That's something I wouldn't have thought of. Thank you! The app works exactly as hoped for!
 

PhoneyDeveloper

macrumors 68040
Sep 2, 2008
3,114
93
OK, I just ran it off of your attachment, and it actually works. That seems... Weird. I did notice you changed a few lines of code, though. Also, in IB, it looks like you have the UIImageView on top of the UIScrollView.
I added a scrollview and set the imageview as its subview in IB. It worked without the scrollview, but the cartoon was scaled to fit the imageView. With the scrollview the imageview is the same size as the image and you scroll to see the whole image.

Also, there was no subview of scrollView added. Was the scrolling just used as a way of viewing the entire part of the screen that the image was part of?
Um, what else? That's what a scrollview is for.

That's something I wouldn't have thought of. Thank you! The app works exactly as hoped for!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.