首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NSOperationQueue实现

NSOperationQueue实现
EN

Stack Overflow用户
提问于 2011-09-22 15:01:57
回答 2查看 389关注 0票数 0

在加载一些数据时,我显示了一个带有“请稍候”文本的UIAlertView,让用户知道现在正在处理某些内容。

因此我将UIAlertView隐藏在- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath函数中,如下所示

因此,现在我需要知道的是,我是否以正确的方式处理NSOperationQueue?还是我在使用NSOperationQueue时遗漏了什么?

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

谢谢

代码语言:javascript
复制
-(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;   
}
EN

回答 2

Stack Overflow用户

发布于 2011-09-22 15:10:25

您可以查看适用于NSOpeationQueue的this示例。

还有this one。

票数 1
EN

Stack Overflow用户

发布于 2011-09-22 15:15:05

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7510818

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档