LeoSam
LeoSam

Reputation: 4941

UIImageView image not showing up at all

im using the followng method , to display image when a timestamp detecetd , am using dispatch_async(dispatch_get_main_queue(), to do UIImageView , its never works its should open a new screen full size image that it ,

        dispatch_async(dispatch_get_main_queue(), ^{



            UIImage *myImage = [UIImage imageNamed:@"img.jpg"];

            UIImageView *myImageView = [[UIImageView alloc] initWithImage:myImage];

            [myImageView setFrame:CGRectMake(0, 0, 100, 200)];

            [myImageView release];
       ;
       });

my full code

 - (void) onPayload:(PayloadEvent *) event

{

NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

NSString *header = @"[OnPayload] ";

if (event.payloadType == TYPE_IDENTIFIED)

{


    if ((event.contentID != -1) && (event.timeStamp == -1))

    {

        [mUI performSelectorOnMainThread: @selector(Trace:) withObject:[NSString stringWithFormat:@"%@ StaticID detected: %x\t\tConfidence: %f\n", header,(int)event.contentID, event.confidence]  waitUntilDone:NO];

    }

    if ((event.timeStamp != -1) && (event.contentID == -1))



    {

        [mUI performSelectorOnMainThread: @selector(Trace:) withObject:[NSString stringWithFormat:@"%@ Timestamp detected: %f\t\tConfidence: %f\n", header, event.timeStamp, event.confidence]  waitUntilDone:NO];
 dispatch_async(dispatch_get_main_queue(),  ^{

            UIImage *myImage = [UIImage imageNamed:@"img.jpg"];

            UIImageView *myImageView = [[UIImageView alloc] initWithImage:myImage];

            [myImageView setFrame:CGRectMake(0, 0, 100, 200)];

            [myImageView release];



;  });

Upvotes: 0

Views: 2068

Answers (3)

Bruno Koga
Bruno Koga

Reputation: 3874

You are creating an ImageView, assigning an Image to it and releasing the ImageView. In other words, you're not displaying the ImageView anywhere.

If you can't do something like [self.view addSubview:imageView], it means that you're not running this code on a UIViewController subclass.

You basically need to add this ImageView you're creating as a subview for the current view before releasing it.

In which class are you running this code? Do you know which View Controller is currently being displayed?

Upvotes: 1

Dharmbir Singh
Dharmbir Singh

Reputation: 17535

Try to use this one in your code.

[self.view addSubview:myImageView];

Upvotes: 1

user529758
user529758

Reputation:

You never add myImageView to any view as a subview.

Upvotes: 1

Related Questions