way to start activity indicator on click event of button before its touch ends?

不想你离开。 提交于 2019-12-11 03:14:30

问题


i working on uploading the images through my application.i used the following code

-(IBAction)submitimage:(id)sender
{
        // [activity startAnimating]; i started activity here but it starts after completion of function 
    NSString *name, *comments;
    comments = txtcomment.text;
    name = @"Anonymous";
    int r=random()%10000;
    NSLog(@"random number:%d",r );
    NSString *imageName=[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"dashboard\"; filename=\"%d.jpg\"\r\n",r];

    NSData *imageData = UIImageJPEGRepresentation(imge, 90);
        //NSLog(@"imagedata=%@",imageData);
    NSString *urlString =[NSString stringWithFormat:@"http://www.xyzsite.com/webservices/&comment=%@&name=%@",comments,name];



        //NSLog(@"urlsubmit=%@",urlString);
    NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
    [request setURL:[NSURL URLWithString:urlString]];
    [request setHTTPMethod:@"POST"];
    NSString *boundary = [NSString stringWithString:@"---------------------------14737809831466499882746641449"];
    NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary];
    [request addValue:contentType forHTTPHeaderField: @"Content-Type"];

    /*  body of the post */
    NSMutableData *body = [NSMutableData data];
    [body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]]; 
    [body appendData:[[NSString stringWithString:imageName] dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[[NSString stringWithString:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[NSData dataWithData:imageData]];
    [body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
    [request setHTTPBody:body];
    NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
    NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
    NSLog(@"%@",returnString); 
}

but the animation starts after function over so is there any other way to start activity indicator.before the touch event over.i face the same problem in two different application of uploading images.so if anyone knows then plese let me know thanks


回答1:


There could be more than one solution to this. However you can move the activity indication start animation action to the TouchDown event and leave the other in Touch up Inside.



来源:https://stackoverflow.com/questions/7454252/way-to-start-activity-indicator-on-click-event-of-button-before-its-touch-ends

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!