Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 07-03-2010, 02:29 AM   #1 (permalink)
Registered Member
 
Join Date: Jan 2009
Posts: 54
nenos is on a distinguished road
Default Need UIImageView inside UIScrollView to change

Hey,

I have an UIImageView hooked up to the UIScrollView. All I want is to replace the image on the scrollview whenever a table cell is selected. So far what happens is that whenever I select a cell, the new image is added on top of the old image rather than replacing them.

Any help is appreciated.
nenos is offline   Reply With Quote
Old 07-03-2010, 03:01 PM   #2 (permalink)
Registered Member
 
Join Date: May 2009
Location: Texas
Posts: 57
Lebowski is on a distinguished road
Cool

So, what I'm guessing you are trying to do is to display an image that requires scrolling. The image displayed is based on user input in the form of a cell selection from a table view. If that is your intention, there is an excellent tutorial that sort of explains this. Here it is:

UITableView - Loading a detail view - iPhone SDK Articles

All you have to do display the image in a scrollview instead of an image view. You can also display it in the rootviewcontroller (which in this case is a tableview that already scrolls).

One of my applications does this and I found this tutorial very helpful. I hope this is what you need. Best of luck.
Lebowski is offline   Reply With Quote
Old 07-04-2010, 05:51 AM   #3 (permalink)
Registered Member
 
Join Date: Jan 2009
Posts: 54
nenos is on a distinguished road
Default

Hey Lebowski,

Thanks for the reply I already have the tableview all set, and the scrollview with an imageview inside of it. My problem is that whenever a different cell is selected, the image doesn't get replaced, but a new layer is added on top of the previous image. I'm working on the iPad's split view-based controller. Instead of adding a new layer of the image on top of the previous one, I want the image inside of the uiimageview to be replaced with the new image that is selected from the tableview cell.

This is what I have so far...

- (void)tableViewUITableView *)aTableView didSelectRowAtIndexPathNSIndexPath *)indexPath {

if (indexPath.section == 0) {
if (indexPath.row == 0) {
detailViewController.imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"1.png"]];
}
if (indexPath.row == 1) {
detailViewController.imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"1-2.png"]];
}
}
nenos is offline   Reply With Quote
Old 07-04-2010, 02:01 PM   #4 (permalink)
Registered Member
 
Ice_2k's Avatar
 
Join Date: Apr 2010
Location: Bucharest, Romania
Posts: 148
Ice_2k is on a distinguished road
Default

You could try updating the image instead of creating a new image view:

detailViewController.imageView.image = [UIImage imageNamed .....];
Ice_2k is offline   Reply With Quote
Old 07-04-2010, 07:29 PM   #5 (permalink)
Registered Member
 
Join Date: Jan 2009
Posts: 54
nenos is on a distinguished road
Default

Quote:
Originally Posted by Ice_2k View Post
You could try updating the image instead of creating a new image view:

detailViewController.imageView.image = [UIImage imageNamed .....];
Oh cool thanks Ice_2k, I still have one problem, scrollview doesn't scroll anymore, whereas before when I used the previous method, it did, and I have "[detailViewController.scrollView setScrollEnabled:YES];" but it doesn't scroll.
nenos is offline   Reply With Quote
Old 07-05-2010, 01:08 AM   #6 (permalink)
Registered Member
 
Ice_2k's Avatar
 
Join Date: Apr 2010
Location: Bucharest, Romania
Posts: 148
Ice_2k is on a distinguished road
Default

There is a method that tells the scrollview how much it should scroll, setContentOffset is called I believe. Try calling this method with your desired scroll distance (the image height + whatever else you have on your view).
Ice_2k is offline   Reply With Quote
Old 07-05-2010, 07:31 PM   #7 (permalink)
Registered Member
 
Join Date: Jan 2009
Posts: 54
nenos is on a distinguished road
Default

Quote:
Originally Posted by Ice_2k View Post
There is a method that tells the scrollview how much it should scroll, setContentOffset is called I believe. Try calling this method with your desired scroll distance (the image height + whatever else you have on your view).
Thanks Ice_2k, I tried that method but it still doesnt work lol
nenos is offline   Reply With Quote
Old 07-06-2010, 01:46 AM   #8 (permalink)
Registered Member
 
Ice_2k's Avatar
 
Join Date: Apr 2010
Location: Bucharest, Romania
Posts: 148
Ice_2k is on a distinguished road
Default

Can you post the code you used to update the image?
Ice_2k is offline   Reply With Quote
Old 07-06-2010, 07:19 AM   #9 (permalink)
Registered Member
 
Join Date: Jan 2009
Posts: 54
nenos is on a distinguished road
Default

Quote:
Originally Posted by Ice_2k View Post
Can you post the code you used to update the image?
Yeh sure, here it is...

if (indexPath.section == 0) {
if (indexPath.row == 0) {
detailViewController.imageView.image = [UIImage imageNamed:@"1.png"];
detailViewController.scrollView.clipsToBounds = NO;
detailViewController.scrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
[detailViewController.scrollView addSubview:detailViewController.imageView];
[detailViewController.scrollView setContentSize:CGSizeMake(detailViewController.ima geView.frame.size.width, detailViewController.imageView.frame.size.height)];
[detailViewController.scrollView setScrollEnabled:YES];

}
if (indexPath.row == 1) {
detailViewController.imageView.image = [UIImage imageNamed:@"1-2.png"];
detailViewController.scrollView.clipsToBounds = NO;
detailViewController.scrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
[detailViewController.scrollView addSubview:detailViewController.imageView];
[detailViewController.scrollView setContentSize:CGSizeMake(detailViewController.ima geView.frame.size.width, detailViewController.imageView.frame.size.height)];
[detailViewController.scrollView setScrollEnabled:YES];
}

}
nenos is offline   Reply With Quote
Old 07-06-2010, 08:07 AM   #10 (permalink)
Registered Member
 
Ice_2k's Avatar
 
Join Date: Apr 2010
Location: Bucharest, Romania
Posts: 148
Ice_2k is on a distinguished road
Default

First of all, I'm not sure you should be using addSubView all the time. You should just add it in viewDidLoad (or in IB) and then just update its image. The way you're doing it, you're just adding the same view over and over again. I have no idea what side-effects that would have. Second, are you sure you're image view's size is updated along with the image? I think you should use the image's size and not the view's. Run this code in debug mode to figure out what the issue is:

Code:
int viewW = detailViewController.imageView.size.width;
int viewH = detailViewController.imageView.size.height;
int imageW = detailViewController.imageView.image.size.width;
int imageH = detailViewController.imageView.image.size.height;
If the height of the view is not the same as the height of the image, there's your problem.
Ice_2k is offline   Reply With Quote
Old 07-08-2010, 12:55 AM   #11 (permalink)
Registered Member
 
Join Date: Jan 2009
Posts: 54
nenos is on a distinguished road
Default

Quote:
Originally Posted by Ice_2k View Post
First of all, I'm not sure you should be using addSubView all the time. You should just add it in viewDidLoad (or in IB) and then just update its image. The way you're doing it, you're just adding the same view over and over again. I have no idea what side-effects that would have. Second, are you sure you're image view's size is updated along with the image? I think you should use the image's size and not the view's. Run this code in debug mode to figure out what the issue is:

Code:
int viewW = detailViewController.imageView.size.width;
int viewH = detailViewController.imageView.size.height;
int imageW = detailViewController.imageView.image.size.width;
int imageH = detailViewController.imageView.image.size.height;
If the height of the view is not the same as the height of the image, there's your problem.
hey,

thanks for the reply.

1) I added the methods to the viewDidLoad and left the if's with the method of swapping the images

2) I have images which are really tall in height, and I want them to be like that, do they have to be the same height as the view? How do you use that code to check it?

Sorry I'm not a pro at xcode lol
nenos is offline   Reply With Quote
Old 07-08-2010, 01:53 AM   #12 (permalink)
Registered Member
 
Ice_2k's Avatar
 
Join Date: Apr 2010
Location: Bucharest, Romania
Posts: 148
Ice_2k is on a distinguished road
Default

You set a breakpoint on the code I gave you and check the results as each statement is executed.
Ice_2k is offline   Reply With Quote
Old 07-11-2010, 02:20 PM   #13 (permalink)
Registered Member
 
Join Date: Mar 2010
Posts: 14
themaccity is on a distinguished road
Default

I am in the same scenario, where I need the image in the imageView to change based on the cell, and I have this code in my didSelectRowAtIndexPath method:

if (indexPath.row == 0) {
detailViewController.imageView.image = [UIImage imageNamed:@"1.png"];

}

i don't have anything else because everything else is handled in my DetailViewController (e.g. scrollView.clipsToBounds, etc.)

however when I build the project I get an error that says "Request for member "imageView" in something not a structure or a union"
__________________
themaccity

Buy my app, QuickTipper today!
http://bit.ly/quicktipperdownload

Follow me on Twitter!
http://twitter.com/themaccity

Subscribe to me on Youtube!
http://youtube.com/themaccity
themaccity is offline   Reply With Quote
Old 07-11-2010, 02:22 PM   #14 (permalink)
Registered Member
 
Ice_2k's Avatar
 
Join Date: Apr 2010
Location: Bucharest, Romania
Posts: 148
Ice_2k is on a distinguished road
Default

Quote:
Originally Posted by themaccity View Post
I am in the same scenario, where I need the image in the imageView to change based on the cell, and I have this code in my didSelectRowAtIndexPath method:

if (indexPath.row == 0) {
detailViewController.imageView.image = [UIImage imageNamed:@"1.png"];

}

i don't have anything else because everything else is handled in my DetailViewController (e.g. scrollView.clipsToBounds, etc.)

however when I build the project I get an error that says "Request for member "imageView" in something not a structure or a union"
The compiler doesn't know who detailViewController is (or what type it is).
Ice_2k is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 321
6 members and 315 guests
anothermine, Chickenrig, givensur, michaelhansen, PixelInteractive, stanny
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,657
Threads: 94,118
Posts: 402,892
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jenniead38
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 12:26 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0