NSOperationQueue Реализация - PullRequest
       0

NSOperationQueue Реализация

0 голосов
/ 22 сентября 2011

Я показал UIAlertView с текстом «Пожалуйста, подождите» при загрузке некоторых данных, чтобы дать пользователю знать, что что-то сейчас обрабатывается.

Поэтому я скрываю UIAlertView в табличном представлении - (UITableViewCell *): (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;   
}

Ответы [ 2 ]

1 голос
/ 22 сентября 2011

Вы можете увидеть этот пример, который подходит для NSOpeationQueue.
А также это один.

0 голосов
/ 22 сентября 2011

Вы не должны выпускать NSOperationQueue сразу после его создания, а хранить ссылку на него в своем классе и освобождать его, когда ваш класс освобожден.В противном случае возможно, что ваши операции не будут выполнены.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...