Hello all,
I've my own class which should do the request and the data processing (parsing). This class should be used from different view controllers. In this class I have implemented:
- (void)sendRequest:(NSString *)url;
- (void)requestFinished:(ASIHTTPRequest *)request;
- (void)requestFailed:(ASIHTTPRequest *)request;
- (id)parse:(NSString *)aString;
I have created a property called result. If the request arrives, requestFinished is called. In requestFinished the results are saved in result. I thought if I return a value in sendRequest I get the result back. But as I mentioned before requestFinished gets the result and so sendRequest is always returning a nil variable, because at that time the request isn't finished.
What can I do to return a result? I want that this class can be used from different view controllers. So my first thought creating a method in my view controller and passing the result won't work.
I read this thread http://stackoverflow.com/questions/2878640/pass-result-of-asihttprequest-requestfinished-back-to-originating-method about using the view controller as delegate. But then I think I have to implement requestFinished and requestFailed in the view controller. The idea of not having duplicate code in different view controllers would be gone away ...
Can someone help?