2011-09-22 33 views
0

我已经显示UIAlertView与“请稍候”文本,同时加载一些数据,让用户知道现在正在处理的东西。NSOperationQueue Implementedation

所以我躲进了UIAlertView - (UITableViewCell的*)的tableView:(UITableView的*)的tableView的cellForRowAtIndexPath:(NSIndexPath *)indexPath功能如下

所以现在我需要知道的是我在处理NSOperationQueue以正确的方式?或者我错过了什么使用NSOperationQueue

这是我的代码。请让我知道你的想法。

感谢

-(void)buttonPressed 
{ 
alertLoading =[[UIAlertView alloc] initWithTitle:@"Loading Data" message:@"Please wait..." delegate:self cancelButtonTitle:nil otherButtonTitles:nil]; 
     av=[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; 
     [av startAnimating]; 
     [av setFrame:CGRectMake(125, 70, 37, 37)]; 
     //[self.view addSubview:alertLoading]; 
     [alertLoading show]; 
     [alertLoading addSubview:av]; 
     [av release]; 

     NSOperationQueue *queue = [NSOperationQueue new]; 
     NSInvocationOperation *operation = [[NSInvocationOperation alloc] 
              initWithTarget:self 
              selector:@selector(parsing) 
              object:nil]; 
     [queue addOperation:operation]; 
     [operation release]; 
     [queue release]; 
} 

-(void)parsing 
{ 
    NSString *searchUrl = [NSString stringWithFormat:@"%@profile.php?type=list&logged_id=%@&start=%d& rows=%d",ConstantURL,Reg_UserId_Trim,row_index,per_page]; 


    NSURL *xmlURL = [NSURL URLWithString:searchUrl]; 

    NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithContentsOfURL:xmlURL]; 

    parserXML =[[XMLParser alloc]initXMLParser]; 

    profileName = [[ProfileName alloc]init]; 

    myProfileParser =[[MyProfileParser alloc]initMyProfileParser]; 

    //set the Delegate 
    [xmlParser setDelegate:parserXML]; 

    BOOL success = [xmlParser parse]; 

    if (success) 
    { 
     NSLog(@"Successfully Executed"); 
     [myTableView reloadData]; 
    } 
    else 
    { 
     NSLog(@"Error is occured"); 
    } 

    [av stopAnimating]; 

    [self performSelectorOnMainThread:@selector(loadPageDetails) withObject:nil waitUntilDone:NO]; 

    [myTableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:YES]; 
} 




// Customize the appearance of table view cells. 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    if (cell == nil) 
    { 

    } 

    [alertLoading dismissWithClickedButtonIndex:0 animated:YES]; 

    return cell; 
} 

回答

1

你可以看到this例子,这是很好的NSOpeationQueue。
还有this其中之一。

0

您不应该在创建它之后立即释放NSOperationQueue,而是在您的类中存储对它的引用并在您的类被释放后释放它。 否则有可能您的操作不会被执行。