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 04-09-2011, 08:01 AM   #1 (permalink)
Registered Member
 
Join Date: Apr 2011
Posts: 2
tresnotas is on a distinguished road
Default UIImageView showing the image only after changing tabs in the UITabBarViewController

I have a UIScrollViewController that has a UIScrollView which holds an UIImageView inside. In loadView of the the scroll view controller I download the image by calling a function, that's supposed to do the downloading on a different thread. I call this function from my loadView and then put the imageview inside the scrollview, and set the scrollview as the view of the controller.

The problem is I can't see the image when I run the program, after clicking a row in the tableView (which is supposed to push the scrollview with the image in it). However, if I change tabss (in the tabbarviewcontroller) and come back to this tab. The image will show.

So I think the image download happens, but I somehow have a problem showing it instantly on the screen. It only appears after I come back to it. What do I seem to be doing wrong? I'm new to threads so I suspect it's a problem with that. Also my code was working before I made it so that it would do the download in another thread, so I'm pretty sure it is related to that.

This is the function in the Photo.m which is an Entity in Core Data. This is supposed to do the download

Code:
- (void)processImageDataWithBlock:(void (^)(NSData *imageData))processImage { 
    NSString *url = self.imageURL;
dispatch_queue_t callerQueue = dispatch_get_current_queue();   
dispatch_queue_t downloadQueue = dispatch_queue_create("Flickr download", NULL); 
dispatch_async(downloadQueue, ^{
    NSData *imageData = [FlickrFetcher imageDataForPhotoWithURLString:url];

    dispatch_async(callerQueue, ^{

        processImage(imageData);   

    });

});
}

This is my loadView method in the PhotoScrollViewController.m


Code:
- (void)loadView {

    [image processImageDataWithBlock:^(NSData *imageData) {

        UIImage *imageToBeShown = [UIImage imageWithData:imageData];        


        imageView = [[UIImageView alloc] initWithImage:imageToBeShown];
        CGRect applicationFrame = [[UIScreen mainScreen] applicationFrame];
        scrollView = [[UIScrollView alloc] initWithFrame:applicationFrame];
        scrollView.delegate = self;
        scrollView.contentSize = imageToBeShown.size;

        [scrollView addSubview:imageView];
        self.title = image.title;
        self.view = scrollView;
    }];
      }
tresnotas is offline   Reply With Quote
Reply

Bookmarks

Tags
uiimageview

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: 358
13 members and 345 guests
dansparrow, dre, ilmman, LezB44, michelle, Nobbsy, Objective Zero, samdanielblr, Sami Gh, shagor012, sledzeppelin, thephotographer, tinamm64
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,663
Threads: 94,119
Posts: 402,896
Top Poster: BrianSlick (7,990)
Welcome to our newest member, LezB44
Powered by vBadvanced CMPS v3.1.0

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