即时通讯使用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];
; });
答案 0 :(得分:1)
您永远不会将myImageView
作为子视图添加到任何视图。
答案 1 :(得分:1)
尝试在代码中使用此代码。
[self.view addSubview:myImageView];
答案 2 :(得分:1)
您正在创建ImageView,为其分配图像并释放ImageView。换句话说,您不会在任何地方显示ImageView。
如果您无法执行[self.view addSubview:imageView]
之类的操作,则表示您未在UIViewController
子类上运行此代码。
您基本上需要在发布之前添加此创建的ImageView作为当前视图的子视图。
您在哪个类中运行此代码?您知道当前正在显示哪个View Controller吗?