tags:

views:

920

answers:

2

I am trying to implement a simple TTURLRequest in my app. I'm pretty new to the Three20 framework. I mainly want TTURLRequest and TTImageView for the awesome caching stuff.

I have the following code in my delegate:

- (void)requestDidFinishLoad:(TTURLRequest*)request {
    TTURLDataResponse *response = request.response;
    // Stuff to process response.data
}

response is always nil. I can't figure out what I'm doing wrong. I looked in the Application Support directory and it's creating the cache file with the proper data, so I know it's getting a response. What am I doing wrong?

A: 

Mark Allen from revetkn.com posted a datasource implementation for TTURLRequest.

He also posted an example project where he assumes you have Three20 installed at ../ (relative to your project). It's here: http://revetkn.com/?p=72

I tried doing it the same way he does in his example and it still doesn't work. Here is a sample project:http://dl.getdropbox.com/u/67797/Untitled.zipWhat am I doing wrong?
Sam Soffes
+5  A: 

Debugged your code - you actually have to create a response object and add it to the request before sending your request:

NSString *url = @"http://twitter.com/statuses/user_timeline/samsoffes.json?count=1";
TTURLRequest *theRequest = [[TTURLRequest alloc] initWithURL:url delegate:self];
theRequest.response = [[[TTURLDataResponse alloc] init] autorelease];
[theRequest send];

One would think the request would be in charge of creating the response, but the Three20 stuff doesn't.

Steve Brewer
This one has been a bit counter-intuitive since Joe released Three20. I believe that the reason is that this puts the requestor in charge of deciding whether they expect a binary TTURLDataResponse or a TTURLImageResponse.I think it might make sense to propose an additional convenience initializer method that has an additional parameter to select which response type is desired, and is turned instantiated by TTURLRequest's own init code.
Justin Searls