[英]NSOperationQueue Implemetation
I have shown a UIAlertView
with "Please Wait" text while loading some data to let the user to know that something is being processing now. 在加载一些数据时,我已经显示了带有“ Please Wait”文本的UIAlertView
,以使用户知道正在处理某些内容。
So I hide the UIAlertView
in the - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath Function as below 所以我将UIAlertView
隐藏在-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath函数中,如下所示
So now what I need to know is am I handling the NSOperationQueue
in a correct manner? 因此,现在我需要知道的是我是否以正确的方式处理NSOperationQueue
? or am I missing anything in using NSOperationQueue
还是我在使用NSOperationQueue
时缺少任何东西
Here is my code. 这是我的代码。 please let me know your thoughts. 请让我知道你的想法。
Thanks 谢谢
-(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;
}
You should not release the NSOperationQueue immediately after its creation, but rather store a reference to it in your class and release it when your class is deallocated. 您不应该在创建NSOperationQueue后立即释放它,而应将对它的引用存储在您的类中,并在释放类时释放它。 Otherwise is possible that your operations won't be executed. 否则可能无法执行您的操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.