views:

59

answers:

1

Hello!

I want to change an uiimage.image by calling a method in my viewcontroller:

-(void) aendereBild: (NSData*)bildngage {
    UIImage *uiimageAusData = [UIImage imageWithData: bildngage];
    drawImage.image = uiimageAusData;
}

To make it short: The image is not changing. This is not due to the NSData I pass (which i first thought was the problem). This method is called from the appdelegate.

In another void in this viewcontroller I can change the image with drawimage.image = otherimage without any problems, so I think the call from the AppDelegate is causing the problem. Anyone an idea what I did wrong? Thankie!

A: 

I think @tonclon has it right that the call from the appDelegate isn't happening in the right thread. An easy way to check is to put a breakpoint on the line that works and the line that doesn't and look at what thread is being used (shown in the Xcode debugger).

This question shows you how you do the update in the right thread if that's the case:

http://stackoverflow.com/questions/805410/how-do-i-update-the-ui-in-the-middle-of-this-thread

You need something like

  [drawImage performSelectorOnMainThread:@selector(setImage:) withObject:uiimageAusData waitUntilDone:NO];

The threads that make calls onto the appDelegate aren't necessarily the main thread -- you should check. Your app starts with a few threads, even if you didn't make any.

Lou Franco
As far as I can see both functions are called by thread 1...
Is the app delegate calling it after viewDidLoad and before viewDidUnload? Is the image the same as when it works? Can you try making some other change (perhaps to a UILabel's text).
Lou Franco
1st: yes2nd: no. its a hand-drawn line. But I also tried to exchange it with another picture I use, it doesnt work (it´s not the image thats causing the problem I think)3rd: I just tried to manipulate center.x and center.y of another image with the same function. it doesnt work.I guess its the call by the appdelegate. no idea why. During this breakpointtesting I saw that the first breakpoint was called when the view wasnt on the screen (we were still on the splashscreen). Maybe that´s the problem?
Anyone an idea?
I think the view doesn't know that it's invalid. Call setNeedsDisplay on it
Lou Franco
Doesnt work. I call my method with this code from appDelegate: FirstViewController *theInstance = [[FirstViewController alloc] init]; [theInstance aendereBild: bildngage];
oh. You are creating a new instance -- not talking to the one that's already there. That instance isn't on the screen. You have to get the view controller that's already in the window to the appdelegate
Lou Franco
Oh... How do I do that?
I don't know what template you started out with. In a View-based app, the appDelegate has a pointer to the window and ViewController. I think the navigation template does something similar. If it's another viewcontroller (not the first one or root one), you should arrange for the first one to pass it's delegate on to the next one and then have it tell the delegate about itself.
Lou Franco
I used a Tab-Template for it.
Solution was to tell tabbarcontroller.delegate=self in the appdelegate. Then it´s working.