如何通过解析添加活动指示器?

发布于 2024-12-01 03:53:13 字数 1904 浏览 1 评论 0原文

我想在单击表视图的行时添加活动指示器或 MBProgressHUD,并在下一个视图的表 laod 时消失。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == 1 && indexPath.row == 0) {
    /*here add activity indiavtor*/

    iMapViewAppDelegate *appDelegate = (iMapViewAppDelegate *)[[UIApplication sharedApplication] delegate];
    NSString *requestString = [NSString stringWithFormat:@"http://maps.googleapis.com/maps/api/directions/xml?origin=%@&destination=%@,OK&sensor=false",startField.text,endField.text]; 
    NSURL *url = [[NSURL alloc] initWithString:requestString];
    NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithContentsOfURL:url];

    //Initialize the delegate.
    xml1 *parser = [[xml1 alloc] init];

    //Set delegate
    [xmlParser setDelegate:parser];


    //Start parsing the XML file.
    BOOL success = [xmlParser parse];


    if(success){
        NSLog(@"No Errors");
        appDelegate.legAray=[parser.listofPoint copy];
        appDelegate.sAray=[parser.ListofSteps1 copy];
        arySteps=[[NSArray alloc]init];
        arySteps = [parser.ListofSteps1 arrayByAddingObjectsFromArray:parser.listofPoint];
        appDelegate.NoofRow=0;
        appDelegate.NoofRow=[arySteps count];
        NSLog(@"%d",appDelegate.NoofRow);
        NSLog(@"%@",arySteps);
        sObject=[[Sleg alloc]init];
        sObject=[appDelegate.legAray objectAtIndex:0];

    }
    else
        NSLog(@"Error Error Error!!!");


        controller= [TableView alloc];
        controller.arayStep=[arySteps copy];
        [controller initWithNibName:@"TableView" bundle:nil];
        [self.navigationController pushViewController:controller animated:YES];
        [controller release];
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

} 上面的代码用于选择行。当此函数调用时,然后查看添加活动指示器或 MBProgressHUD 并在下一个视图中释放。怎么办呢?

I want to add activity indicator or MBProgressHUD when i click on row of table view and disapear when next view's table laod.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == 1 && indexPath.row == 0) {
    /*here add activity indiavtor*/

    iMapViewAppDelegate *appDelegate = (iMapViewAppDelegate *)[[UIApplication sharedApplication] delegate];
    NSString *requestString = [NSString stringWithFormat:@"http://maps.googleapis.com/maps/api/directions/xml?origin=%@&destination=%@,OK&sensor=false",startField.text,endField.text]; 
    NSURL *url = [[NSURL alloc] initWithString:requestString];
    NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithContentsOfURL:url];

    //Initialize the delegate.
    xml1 *parser = [[xml1 alloc] init];

    //Set delegate
    [xmlParser setDelegate:parser];


    //Start parsing the XML file.
    BOOL success = [xmlParser parse];


    if(success){
        NSLog(@"No Errors");
        appDelegate.legAray=[parser.listofPoint copy];
        appDelegate.sAray=[parser.ListofSteps1 copy];
        arySteps=[[NSArray alloc]init];
        arySteps = [parser.ListofSteps1 arrayByAddingObjectsFromArray:parser.listofPoint];
        appDelegate.NoofRow=0;
        appDelegate.NoofRow=[arySteps count];
        NSLog(@"%d",appDelegate.NoofRow);
        NSLog(@"%@",arySteps);
        sObject=[[Sleg alloc]init];
        sObject=[appDelegate.legAray objectAtIndex:0];

    }
    else
        NSLog(@"Error Error Error!!!");


        controller= [TableView alloc];
        controller.arayStep=[arySteps copy];
        [controller initWithNibName:@"TableView" bundle:nil];
        [self.navigationController pushViewController:controller animated:YES];
        [controller release];
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

}
above code is for selecting row.In when this function call then view add activity indicator or MBProgressHUD and release in next view. How do that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夏末 2024-12-08 03:53:13
(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == 1 && indexPath.row == 0) 
{

    chkIndexPath = indexPath.row;    
    activity.hidden = FALSE;
    [activity startAnimating];

    [self performSelector:@selector(myFunction) withObject:nil afterDelay:0.0];
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}
- (void)myFunction
{
  //your code. use chkIndexPath instead of indexPath.row
}

viewwillAppear 中设置 activity.hidden = TRUE;

(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == 1 && indexPath.row == 0) 
{

    chkIndexPath = indexPath.row;    
    activity.hidden = FALSE;
    [activity startAnimating];

    [self performSelector:@selector(myFunction) withObject:nil afterDelay:0.0];
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}
- (void)myFunction
{
  //your code. use chkIndexPath instead of indexPath.row
}

set activity.hidden = TRUE; in viewwillAppear.

牵你手 2024-12-08 03:53:13

iRam11,
只需实现此代码并询问您是否有任何问题。
NextView.h
声明

UIAlertView *av;
UIActivityIndicatorView *actIndicator;

NextView.m

in viewWillAppear call this callWebService Method

-(void)callWebService {
av = [[UIAlertView alloc] initWithTitle:@"Loading..." message:@"Please wait..." delegate:self cancelButtonTitle:nil otherButtonTitles:nil];
actIndicator = [[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge] autorelease];
[actIndicator setFrame:CGRectMake(120, 70, 40, 40)];
[actIndicator setHidesWhenStopped:YES];
[av addSubview:actIndicator];
[actIndicator startAnimating];
[av show];
[av release];


//Do you web service call
}

-(void)parserDidEndDocument:(NSXMLParser *)parser {
    // Do you tableview reload.
    [av dismissWithClickedButtonIndex:0 animated:YES];
    actIndicator.hidden = YES;
}

iRam11,
Just implement this code and ask if you have any problem.
NextView.h
Declare

UIAlertView *av;
UIActivityIndicatorView *actIndicator;

NextView.m

in viewWillAppear call this callWebService Method

-(void)callWebService {
av = [[UIAlertView alloc] initWithTitle:@"Loading..." message:@"Please wait..." delegate:self cancelButtonTitle:nil otherButtonTitles:nil];
actIndicator = [[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge] autorelease];
[actIndicator setFrame:CGRectMake(120, 70, 40, 40)];
[actIndicator setHidesWhenStopped:YES];
[av addSubview:actIndicator];
[actIndicator startAnimating];
[av show];
[av release];


//Do you web service call
}

-(void)parserDidEndDocument:(NSXMLParser *)parser {
    // Do you tableview reload.
    [av dismissWithClickedButtonIndex:0 animated:YES];
    actIndicator.hidden = YES;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文