簡體   English   中英

NSOperationQueue實現

[英]NSOperationQueue Implemetation

在加載一些數據時,我已經顯示了帶有“ Please Wait”文本的UIAlertView ,以使用戶知道正在處理某些內容。

所以我將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;   
}

您可以看到示例對NSOpeationQueue很有用。
還有這個

您不應該在創建NSOperationQueue后立即釋放它,而應將對它的引用存儲在您的類中,並在釋放類時釋放它。 否則可能無法執行您的操作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM