0

我使用followng方法,在检测到时间戳时显示图像,我正在使用dispatch_async(dispatch_get_main_queue(),做UIImageView,它永远不会工作它应该打开一个新的屏幕全尺寸图像,

        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];
       ;
       });

我的完整代码

 - (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];



;  });
4

3 回答 3

1

尝试在您的代码中使用这个。

[self.view addSubview:myImageView];
于 2013-05-29T10:40:00.927 回答
1

您正在创建一个 ImageView,为其分配一个 Image 并释放 ImageView。换句话说,您不会在任何地方显示 ImageView。

如果您不能执行类似的操作[self.view addSubview:imageView],则意味着您没有在UIViewController子类上运行此代码。

您基本上需要在发布之前将您正在创建的这个 ImageView 添加为当前视图的子视图。

您在哪个班级运行此代码?你知道当前显示的是哪个 View Controller 吗?

于 2013-05-29T14:51:49.527 回答
1

您永远不会将myImageView任何视图添加为子视图。

于 2013-05-29T10:34:33.080 回答