I have a webservice and ios application. I use ASIHTTPRequest.h, ASIFormDataRequest.h headers to handle connection to my php scripts/mysql database
In one of the viewcontrollers I need to send multiple request to my web service and handle each response, and viewcontroller’s view and methods are needed to refresh after each request.
ASIHTTPRequest has only one (void)requestFinished:(ASIHTTPRequest *)request event so I need to handle my responses in blocks inside of (void)requestFinished:(ASIHTTPRequest *)request to handle the request I come up with idea that maybe I can use a string and when request finishes i can use this string in if statement I wrote following code , but my condition in my requestfinish method if ([checkRequest rangeOfString:@"like"].location != NSNotFound) doesnt work
VoteMe.h
@interface VoteMe : UIViewController<UITextFieldDelegate>{
NSMutableString *checkRequest;
}
@property (retain, nonatomic) NSMutableString *checkRequest;
Vote.m
@synthesize checkRequest;
- (void)viewDidLoad
{
[self showPicture];
}
-(void)showPicture
{
checkRequest =[NSMutableString stringWithString:@"showPicture"];
//request a random picture url, from server
NSURL *url = [NSURL URLWithString:showpicture];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setDelegate:self];
[request startAsynchronous];
}
-(IBAction)voteLike:(id)sender{
checkRequest =[NSMutableString stringWithString:@"like"];
NSURL *url = [NSURL URLWithString:voteup];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setDelegate:self];
[request startAsynchronous];
[self showPicture];
}
- (void)requestFinished:(ASIHTTPRequest *)request
{
if ([checkRequest rangeOfString:@"like"].location != NSNotFound) {
//do smth
}
if ([checkRequest rangeOfString:@"showPicture"].location != NSNotFound) {
//do someth else
}
}
The problem of above code when -(IBAction)voteLike:(id)sender is called it supposed to change string of checkRequest to “like” so when response of ASIFormDataRequest arrives if condition can work properly
In break points I see that checkRequest Variable is not a CFString
When I Use Nsstring instead of NSMutableString it is the same result
I know I need retain String then release afterwards but I Dont use alloc should I still need to retain/release
How can I achive my goal? Either a with better solution for checking if statement or fixing NSString and NSmutableString Issue above ?
When you define something as a property (
checkRequest), useself.checkRequestwhen you refer to it in code unless you have a very good reason not to. Those attributes you put on the property statement get ignored if you access the variable directly.