【发布时间】:2012-11-21 21:21:06
【问题描述】:
我的应用程序将查询数据库 50 次,然后通过将正确的 UIImageView 添加到另一个 UIImageView 来做出相应的反应,然后我希望应用程序在每个循环中立即显示。
唉,经过很多个晚上,我都没有让它工作。应用程序不会立即显示 UIImageView。话虽如此,当我在循环中放大或缩小时,UIImageViews 会出现!我一定是错过了什么……
到目前为止,除了最后一部分 [UIScrollView performSelector....
请帮助并提前感谢您。
UIScrollView *firstView;
UIImageView *secondView;
UIImageView *thirdView;
NSOperationQueue *queue;
NSInvocationOperation *operation;
- (void)viewDidAppear:(BOOL)animated
{
queue = [NSOperationQueue new];
operation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(getData) object:nil];
[queue addOperation:operation];
}
- (void) getData
{
for (i=0 ; i < 50 ; i++)
{
//All the codes to facilitate XML parsing here
[nsXMLParser setDelegate:parser];
[BOOL success = [nsXMLParser parse];
if (success)
{
if ([parser.currentValue isEqualToString:@"G"])
thirdView.image = greenTick.jpg;
[secondView addSubview:thirdView];
}
else
{
NSLog(@"Error parsing document!");
}
}
[thirdView performSelectorOnMainThread:@selector(setNeedsDisplay) withObject:nil waitUntilDone: YES];
}
【问题讨论】:
-
“
thirdView”在哪里分配?你在使用 ARC 吗? -
嗨,迈克尔,感谢您的回复。 “第三个视图”在 -(void)viewDidLoad 中分配。像这样 thirdView = [[UIImageView alloc] init];我正在使用 ARC。
标签: ios multithreading setneedsdisplay