PDA

View Full Version : Image Gallery




estupefactika
Mar 3, 2009, 05:38 AM
Hi, what is the best way to make a image gallery? I would like to display my little images and when I click in one of them to open a detail.

a ViewController with UiScrollView?

Any suggestion? Thanks



estupefactika
Mar 3, 2009, 06:43 AM
How can I do the images clickables? with UIButton?

dejo
Mar 3, 2009, 09:00 AM
How can I do the images clickables? with UIButton?
UIImageView is a subclass of UIResponder so you should be able to code it to react to touches, such as touchesBegan:withEvent: or touchesEnded:withEvent:

estupefactika
Mar 3, 2009, 10:40 AM
Ok dejo, I'll look this methods, thanks.

I have a doubt, Ive created several UIImageViews with their tag, if they have image I set it, easy, if it not I'll set later, my question, how can I set the image to my corresponding UIImageView through their tag?

estupefactika
Mar 3, 2009, 11:18 AM
I do this and it works:

UIImageView *img = (UIImageView *)[self.view viewWithTag:tag];

[img setImage:loadImage];

estupefactika
Mar 4, 2009, 03:22 PM
Hi again, Ive created a UIImageView to handle touches there.

When I click an image, in the touchesBegan method, I would like to open a ViewController with their details.

MyClass *viewController= [[MyClass alloc] initWithLink:storyLink];
[[self navigationController] pushViewController:viewController animated:YES];

but my UIImageView not respond to '-navigationController'

What way do I have to use pushViewController correctly?

dejo
Mar 4, 2009, 03:32 PM
...but my UIImageView not respond to '-navigationController'

What way do I have to use pushViewController correctly?
Does your app have a UINavigationController in use?

estupefactika
Mar 4, 2009, 03:47 PM
Yes, in my AppDelegate I have a TabBarController of UINavigationControllers. When I click in the corresponding tabBarItem, I open my image gallery viewController.

dejo
Mar 4, 2009, 04:11 PM
Yes, in my AppDelegate I have a TabBarController of UINavigationControllers. When I click in the corresponding tabBarItem, I open my image gallery viewController.
What is "self" in this line:
[[self navigationController] pushViewController:viewController animated:YES];

and how is it defined? I.E. What does its .h look like?
P.S. Put the .h within [ CODE ] [ /CODE ] tags to make it easier to read here.

estupefactika
Mar 4, 2009, 04:59 PM
A summary:

My AppDelegate has a UITabBarController of UINavigationControllers. When I click in corresponding tabBarItem display my imageGalleryViewController :

imageGalleryViewController:


-(void)loadView {
//Display my image gallery in a ScrollView
//Each image belongs to a press release
for (int i=0;i<[images count];i++) {
...
MyImageViewClass *img=[[MyImageViewClass alloc] initwithFrame:CGRect(...) ];
UIImage *image=[UIImage imageNamed:@"gray.png"];
[img setImage:image];
[scrollView addSubview:img];
....
}

}


My gallery has been displayed.

My UIImageViewClass:
-Each image belongs to a press release, so I would like to open a ViewController with their press release detail.
-I have to get the press release detail in an array. All images is ordered, Example, if I click in the first image, I searh the first index of the array and I get the press release detail.
-Now, I should open my detailViewController to display the press release detail.

-(id) initWithFrame: (CGRect) aFrame {
self=[super initWithFrame:aFrame];
if (!self) return NULL;
return self;
}

-(void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {

UITouch *touch=[[event allTouches] anyObject];
int storyIndex=[touch view].tag;

NSString *storyLink=[[appDelegate.feedArray objectAtIndex:storyIndex] objectForKey:@"url"];

detailViewController *d=[[detailViewController alloc] initWithLink:storyLink];
[[self navigationController] pushViewController:d animated:YES];
}


My detailViewController:

-(id) initWithLink:link {
webView=[[UIWebView alloc] init];
NSString *urlAddress=link;
NSURL *url=[NSURL URLWithString:urlAddress];
NSURLRequest *requestObj=[NSURLRequest requestWithUrl:url];
[self.webView loadRequest:requestObj];
return self;
}


This is what I would like to do, but Ive read that ImageView has not NavigationController, by that dont works. I dont know if Ive explained good, so I dont know how i can to use the pushViewController

dejo
Mar 4, 2009, 05:23 PM
My AppDelegate has a UITabBarController of UINavigationControllers.
Are you sure about this? Because I really doubt that your UITabBarController has a set of UINavigationControllers, from the sound of things. Can you show us the code or Interface Builder inspector where you have set up the View Controllers for each of your tabs?

estupefactika
Mar 5, 2009, 02:38 AM
Here is in my applicationDidFinishLaunching of AppDelegate:

for (int i = 0; i < [buttonNames count]; i++) {
switch (i) {
case 3:
viewController = [[imageGalleryViewController alloc] init];
break;
default:
viewController = [[otherViewController alloc] initWithCategory:i ];
break;
}
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:viewController];
UITabBarItem *tabBarItem = [[UITabBarItem alloc] initWithTitle:[buttonNames objectAtIndex:i] image:[UIImage imageNamed:[imgNames objectAtIndex:i]] tag:i];
nav.tabBarItem = tabBarItem;

[controllers addObject:nav];
[viewController release];
[nav release];
[tabBarItem release];
}

// Create the toolbar and add the view controllers
tabBarController = [[UITabBarController alloc] init];
[tabBarController setViewControllers:controllers animated:YES];
tabBarController.customizableViewControllers = controllers;
tabBarController.delegate = self;

// Set up the window
[window addSubview:tabBarController.view];


It works every tabBarItem, but I dont know how I can to open the press release detail in other view when I click in an image.

The functionality I want is like in photos app, instead of to open a image I open a viewController with a UIView with the press release detail and a 'Back button'

But I unknown what method to use to do the transition to the next view