Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Feb 17, 2011, 04:11 PM   #1
noahgolm
macrumors member
 
Join Date: Aug 2010
UIScrollView not showing the image!

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 is offline   0 Reply With Quote
Old Feb 17, 2011, 04:18 PM   #2
nickculbertson
macrumors regular
 
Join Date: Nov 2010
Location: Nashville, TN
Did you make an IBOutlet for scrollView? Did you connect it in IB?

Nick
__________________
My App Blog --->
nickculbertson is offline   0 Reply With Quote
Old Feb 17, 2011, 04:26 PM   #3
noahgolm
Thread Starter
macrumors member
 
Join Date: Aug 2010
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 is offline   0 Reply With Quote
Old Feb 17, 2011, 04:28 PM   #4
noahgolm
Thread Starter
macrumors member
 
Join Date: Aug 2010
In fact, I'll put up the project, just in case someone wants to look at it. Tis in the attachment!
Attached Files
File Type: zip xkcd.zip (799.8 KB, 43 views)
noahgolm is offline   0 Reply With Quote
Old Feb 17, 2011, 04:35 PM   #5
nickculbertson
macrumors regular
 
Join Date: Nov 2010
Location: Nashville, TN
I don't see the image included in the project folder you attached.
__________________
My App Blog --->
nickculbertson is offline   0 Reply With Quote
Old Feb 17, 2011, 04:37 PM   #6
noahgolm
Thread Starter
macrumors member
 
Join Date: Aug 2010
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!
noahgolm is offline   0 Reply With Quote
Old Feb 17, 2011, 05:11 PM   #7
nickculbertson
macrumors regular
 
Join Date: Nov 2010
Location: 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
__________________
My App Blog --->
nickculbertson is offline   0 Reply With Quote
Old Feb 17, 2011, 06:18 PM   #8
PhoneyDeveloper
macrumors 68030
 
PhoneyDeveloper's Avatar
 
Join Date: Sep 2008
What's the frame of the imageView?

Are you sure that the image isn't nil?
PhoneyDeveloper is online now   0 Reply With Quote
Old Feb 17, 2011, 09:32 PM   #9
noahgolm
Thread Starter
macrumors member
 
Join Date: Aug 2010
Here's a newer version of the project. Same problem!
Attached Files
File Type: zip xkcdApp.zip (1.10 MB, 30 views)
noahgolm is offline   0 Reply With Quote
Old Feb 17, 2011, 09:37 PM   #10
noahgolm
Thread Starter
macrumors member
 
Join Date: Aug 2010
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 by noahgolm; Feb 17, 2011 at 09:44 PM. Reason: Incorrect Markings
noahgolm is offline   0 Reply With Quote
Old Feb 17, 2011, 10:29 PM   #11
PhoneyDeveloper
macrumors 68030
 
PhoneyDeveloper's Avatar
 
Join Date: Sep 2008
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.
Attached Files
File Type: zip xkcdApp.zip (44.5 KB, 64 views)

Last edited by PhoneyDeveloper; Feb 17, 2011 at 10:39 PM.
PhoneyDeveloper is online now   0 Reply With Quote
Old Feb 17, 2011, 10:53 PM   #12
noahgolm
Thread Starter
macrumors member
 
Join Date: Aug 2010
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!
noahgolm is offline   0 Reply With Quote
Old Feb 17, 2011, 11:49 PM   #13
PhoneyDeveloper
macrumors 68030
 
PhoneyDeveloper's Avatar
 
Join Date: Sep 2008
Quote:
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.

Quote:
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.

Quote:
That's something I wouldn't have thought of. Thank you! The app works exactly as hoped for!
PhoneyDeveloper is online now   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Tags
json, sdk, uiimageview, uiscrollview, xkcd

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
iPad Mini: Multitasking Image Showing Deleted Film NOTmacbookpro13 iPad 6 Jan 10, 2014 12:57 PM
Contact Image not showing soamz iPhone 0 Aug 30, 2013 04:15 AM
Why Is My Image Not Showing Up (From Web Service) loon3y iPhone/iPad Programming 0 Sep 18, 2012 11:40 AM
Airplay NOT showing image zerobrand OS X 10.8 Mountain Lion 1 Jul 13, 2012 07:57 PM

Forum Jump

All times are GMT -5. The time now is 05:32 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC