0
我在使用NSOpeation時遇到了一個奇怪的行爲。 我在調用一個函數(-createTagView),它創建一個UIButton然後將其添加到視圖。 由於某些原因,它不會添加它們。如果我從NSOperation之外調用該函數,那麼一切正常。NSOperation不會將子視圖添加到主視圖
任何想法?謝謝。
此我如何創建的NSOperation(一個的ViewController對象內)
> NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(createTagView:) object:data];
> [operationQueue addOperation:operation];
> [operation release];
這是調用的函數([標記視圖]爲的UIButton):
-(void) createTagView:(NSMutableArray *) data
{
NSInteger t_id = (NSInteger)[data objectAtIndex:0];
NSString *t_name = (NSString *)[data objectAtIndex:1];
NSString *t_rawname = (NSString *)[data objectAtIndex:2];
Tag *t = [[Tag alloc] initWithId:(NSInteger)t_id name:t_name rawname:t_rawname];
[self.view addSubview:[t view]];
[t release];
}