1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

Image Gallery

Discussion in 'iPhone/iPad Programming' started by estupefactika, Mar 3, 2009.

  1. macrumors member

    #1
    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
     
  2. macrumors member

    #2
    How can I do the images clickables? with UIButton?
     
  3. Moderator

    dejo

    Staff Member

    #3
    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:
     
  4. macrumors member

    #4
    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?
     
  5. macrumors member

    #5
    I do this and it works:

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

    [img setImage:loadImage];
     
  6. macrumors member

    #6
    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?
     
  7. Moderator

    dejo

    Staff Member

    #7
    Does your app have a UINavigationController in use?
     
  8. macrumors member

    #8
    Yes, in my AppDelegate I have a TabBarController of UINavigationControllers. When I click in the corresponding tabBarItem, I open my image gallery viewController.
     
  9. Moderator

    dejo

    Staff Member

    #9
    What is "self" in this line:
    Code:
    [[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.
     
  10. macrumors member

    #10
    A summary:

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

    imageGalleryViewController:

    Code:
    -(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.
    Code:
    -(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:
    Code:
    -(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
     
  11. Moderator

    dejo

    Staff Member

    #11
    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?
     
  12. macrumors member

    #12
    Here is in my applicationDidFinishLaunching of AppDelegate:
    Code:
    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
     

Share This Page