触摸结束之前如何在按钮的单击事件上启动活动指示器? [英] way to start activity indicator on click event of button before its touch ends?

查看:42
本文介绍了触摸结束之前如何在按钮的单击事件上启动活动指示器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过我的应用程序上传图像.我使用了以下代码

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

推荐答案

对此可能有不止一种解决方案.但是,您可以将活动指示开始动画动作移至TouchDown事件,而将另一个留在"Touch up Inside"中.

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.

这篇关于触摸结束之前如何在按钮的单击事件上启动活动指示器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆