2011-06-01 71 views
-2
threadss.h 
----------- 
#import <Foundation/Foundation.h> 

@interface threadss : NSObject { 

    BOOL m_bRunThread; 
    int a,b,c; 

} 
-(void)startThread; 
-(void)insert; 
-(void)display; 
@end 


threadss.m 
------------ 

import "threadss.h" 

@implementation threadss 
-(void)startThread 
{ 
    m_bRunThread = YES; 
    NSOperationQueue* queue = [[NSOperationQueue alloc]init]; 
    //NSInvocationOperation* operation = [[NSInvocationOperation alloc]initWithTarget:self selector:@selector(display) object:nil]; 
    //[queue addOperation:operation]; 
    [[self insert] performSelectorOnMainThread:@selector(display) withObject:nil waitUntilDone:YES]; 
    [queue release]; 
    //[operation release]; 
} 
-(void)insert 
{ 
    NSLog(@"Into The Insert Event!!"); 
    a=10; 
    b=20; 
    c = a + b; 
} 
-(void)display 
{ 
    NSLog(@"Into the display method"); 
    NSLog(@"The value od c is:%d",c); 
} 
@end 

main.m 
------- 
#import <Foundation/Foundation.h> 
#import "threadss.h" 

int main (int argc, const char * argv[]) { 
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; 

    threadss* thread = [[threadss alloc]init]; 
    [thread startThread]; 

    [pool drain]; 
    return 0; 
} 


error: 
------ 
void value not ignored as it ought to be 

回答

4

你的问题来自这里:

[[self insert] performSelectorOnMainThread:@selector(display) withObject:nil waitUntilDone:YES]; 

[self insert]有一个void返回类型,所以你不能把它作为接收器。

我想你的意思是写:

[self insert]; 
[self performSelectorOnMainThread:@selector(display) withObject:nil waitUntilDone:YES]; 
+0

我的意思是首先调用显示方法,然后我想打电话给插入method.The dispaly方法必须等待插入的方法做处理它应在完成时发出显示线。 – spandana 2011-06-01 12:16:55

+1

如果按照我写的方式执行,插入将在您创建的线程上完成,并在插入完成后在主线程上显示。以该顺序。所以我没有看到回调的原因。 – vakio 2011-06-01 12:37:28

+0

是这样做很容易。而且它并不是完成一项工作。 – spandana 2011-06-01 13:38:20

相关问题