当我点击表视图单元格时,它将在同一个表视图中一段时间(直到下一页完全加载)然后它将显示下一个视图..
我想点击表格视图单元格,它应该立即转到下一页并显示加载页面弹出窗口..
我尝试过使用impActivityAgent并且还尝试在进入下一页时显示警报视图(但是视图是前一页即表视图)..但是......它完全加载页面,这需要时间然后它显示警报..
在下一页我发布并解析需要时间的数据,在此期间我想显示活动指标..
我尝试了很多方法,但它仍然首先完全加载下一页,然后显示内容或alertView或活动指示器,当点击表视图单元格时,我无法显示活动指示器。
我的代码:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
nextTableViewController *doc = [[nextTableViewController alloc]initWithNibName:@"nextTableViewController" bundle:nil];
[self.navigationController pushViewController:doc animated:YES];
}
和下一个视图控制器是:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
[[ImpActivityAgent defaultAgent] makeBusy:YES];
NSURL *loadUrl = [NSURL URLWithString:[NSString stringWithFormat:@"http://%@/gmail.com",inputURL]];
htmlData = [NSData dataWithContentsOfURL:loadUrl];
self.htmlSTR = [[NSString alloc] initWithData:htmlData encoding:NSUTF8StringEncoding];
[self parseHTML];
}
在Parse函数中,我使用“hpple”Parser解析我在HTML格式中得到的内容。
答案 0 :(得分:2)
只需使用一个单独的线程来处理解析。希望这段代码能帮到你。
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
[[ImpActivityAgent defaultAgent] makeBusy:YES];
[NSThread detachNewThreadSelector:@selector(newMethodForParsing) toTarget:self withObject:nil];
}
-(void)newMethodForParsing
{
NSURL *loadUrl = [NSURL URLWithString:[NSString stringWithFormat:@"http://%@/gmail.com",inputURL]];
htmlData = [NSData dataWithContentsOfURL:loadUrl];
self.htmlSTR = [[NSString alloc] initWithData:htmlData encoding:NSUTF8StringEncoding];
[self parseHTML];
[tableView reload]; // tableView refers to ur table view name
}
答案 1 :(得分:1)
试试这个
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[[ImpActivityAgent defaultAgent] makeBusy:YES];
[self performSelectorInBackground:@selector(start) withObject:Nil];
//or you can use after delay then no need to use perform selector on main thread in start method.
[self performSelector:@selector(start) withObject:nil afterDelay:0.5];
}
-(void)start
{
NSURL *loadUrl = [NSURL URLWithString:[NSString stringWithFormat:@"http://%@/gmail.com",inputURL]];
htmlData = [NSData dataWithContentsOfURL:loadUrl];
self.htmlSTR = [[NSString alloc] initWithData:htmlData encoding:NSUTF8StringEncoding];
[self performSelectorOnMainThread:@selector(parseHTML) withObject:Nil waitUntilDone:YES];
}
答案 2 :(得分:0)
试试吧......
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(newMethodForParsing) userInfo:nil repeats:NO];
}
-(void)newMethodForParsing
{
NSURL *loadUrl = [NSURL URLWithString:[NSString stringWithFormat:@"http://%@/gmail.com",inputURL]];
htmlData = [NSData dataWithContentsOfURL:loadUrl];
self.htmlSTR = [[NSString alloc] initWithData:htmlData encoding:NSUTF8StringEncoding];
[self parseHTML];
}
答案 3 :(得分:0)
Ganapathy的回答泄漏了内存,你需要在方法中放置一个autoreleasepool。这是一种更简单的方法。这将在主线程上运行,但在队列中的现有任务之后运行。
如果您希望它在另一个线程上运行,请替换为dispatch_get_global_queue()
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
[[ImpActivityAgent defaultAgent] makeBusy:YES];
dispatch_async(dispatch_get_main_queue(), ^{
NSURL *loadUrl = [NSURL URLWithString:[NSString stringWithFormat:@"http://%@/gmail.com",inputURL]];
htmlData = [NSData dataWithContentsOfURL:loadUrl];
self.htmlSTR = [[NSString alloc] initWithData:htmlData encoding:NSUTF8StringEncoding];
[self parseHTML];
)
}