iphone app: delegate not responding
So i'm very new to this iphone development stuff.... and i'm stuck.

I'm building an app that connects to the twitter api. However when the connectionDidFinishLoading method gets called, it doesn't seem to recognise the delegate.

Here's the source code of the request class:

#import "OnePageRequest.h"


@implementation OnePageRequest

@synthesize username;
@synthesize password;
@synthesize receivedData;
@synthesize delegate;
@synthesize callback;
@synthesize errorCallBack;
@synthesize contactsArray;

-(void)friends_timeline:(id)requestDelegate requestSelector:(SEL)requestSelector{
	//set the delegate and selector
	self.delegate = requestDelegate;
	self.callback = requestSelector;
	
	//Set up the URL of the request to send to twitter!!
	NSURL *url = [NSURL URLWithString:@"http://twitter.com/statuses/friends_timeline.xml"];

	[self request:url];
}

-(void)request:(NSURL *) url{
	
	theRequest = [[NSMutableURLRequest alloc] initWithURL:url];
	theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
	
	if (theConnection){
		//Create the MSMutableData that will hold the received data.
		//receivedData is declared as a method instance elsewhere
		receivedData=[[NSMutableData data] retain];
	}else{
		//errorMessage.text = @"Error connecting to twitter!!";
	}
}

-(void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge{
	
	if ([challenge previousFailureCount] == 0){
		NSLog(@"username: %@ ",[self username]);
		NSLog(@"password: %@ ",[self password]);
		NSURLCredential *newCredential = [NSURLCredential credentialWithUser:[self username]
																	password:[self password]
																 persistence:NSURLCredentialPersistenceNone];
		[[challenge sender] useCredential:newCredential forAuthenticationChallenge:challenge];
	} else {
		[[challenge sender] cancelAuthenticationChallenge:challenge];
		NSLog(@"Invalid Username or password!");
	}
}	

-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{
	
	[receivedData setLength:0];
	
}

-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{
	
	[receivedData appendData:data];
	
}

-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error{
	
	[theConnection release];
	[receivedData release];
	[theRequest release];
	
	NSLog(@"Connection failed. Error: %@ %@", [error localizedDescription], [[error userInfo] objectForKey:NSErrorFailingURLStringKey]);
	
	if(errorCallBack){
		[delegate performSelector:errorCallBack withObject:error];
	}
}

-(void)connectionDidFinishLoading:(NSURLConnection *)connection{
	
	if (delegate && callback){
		if([delegate respondsToSelector:[self callback]]){
			[delegate performSelector:[self callback] withObject:receivedData];
		}else{
			NSLog(@"No response from delegate!");
		}
	}
	[theConnection release];
	[theRequest release];
	[receivedData release];
}



Here's the .h:

@interface OnePageRequest : NSObject {
	
	NSString *username;
	NSString *password;
	NSMutableData *receivedData;
	NSURLRequest *theRequest;
	NSURLConnection *theConnection;
	id	delegate;
	SEL	callback;
	SEL errorCallBack;
	NSMutableArray *contactsArray;
}

@property (nonatomic,retain) NSString *username;
@property (nonatomic,retain) NSString *password;
@property (nonatomic,retain) NSMutableData *receivedData;
@property (nonatomic,retain) id delegate;
@property (nonatomic) SEL	callback;
@property (nonatomic) SEL	errorCallBack;
@property (nonatomic,retain) NSMutableArray *contactsArray;

-(void)friends_timeline:(id)requestDelegate requestSelector:(SEL)requestSelector;
-(void)request:(NSURL *) url;

@end


In the method: connectionDidFinishLoading, the following never gets executed:
[delegate performSelector:[self callback] withObject:receivedData];

Instead I get the message: "No response from delegate"


Anyone see what I'm doing wrong?! or what might be causing the problem?

Regards,
Fiona

iphone app: delegate not responding
===

So i'm very new to this iphone development stuff.... and i'm stuck.

I'm building an app that connects to the twitter api. However when the connectionDidFinishLoading method gets called, it doesn't seem to recognise the delegate.

Here's the source code of the request class:

#import "OnePageRequest.h"


@implementation OnePageRequest

@synthesize username;
@synthesize password;
@synthesize receivedData;
@synthesize delegate;
@synthesize callback;
@synthesize errorCallBack;
@synthesize contactsArray;

-(void)friends_timeline:(id)requestDelegate requestSelector:(SEL)requestSelector{
	//set the delegate and selector
	self.delegate = requestDelegate;
	self.callback = requestSelector;
	
	//Set up the URL of the request to send to twitter!!
	NSURL *url = [NSURL URLWithString:@"http://twitter.com/statuses/friends_timeline.xml"];

	[self request:url];
}

-(void)request:(NSURL *) url{
	
	theRequest = [[NSMutableURLRequest alloc] initWithURL:url];
	theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
	
	if (theConnection){
		//Create the MSMutableData that will hold the received data.
		//receivedData is declared as a method instance elsewhere
		receivedData=[[NSMutableData data] retain];
	}else{
		//errorMessage.text = @"Error connecting to twitter!!";
	}
}

-(void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge{
	
	if ([challenge previousFailureCount] == 0){
		NSLog(@"username: %@ ",[self username]);
		NSLog(@"password: %@ ",[self password]);
		NSURLCredential *newCredential = [NSURLCredential credentialWithUser:[self username]
																	password:[self password]
																 persistence:NSURLCredentialPersistenceNone];
		[[challenge sender] useCredential:newCredential forAuthenticationChallenge:challenge];
	} else {
		[[challenge sender] cancelAuthenticationChallenge:challenge];
		NSLog(@"Invalid Username or password!");
	}
}	

-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{
	
	[receivedData setLength:0];
	
}

-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{
	
	[receivedData appendData:data];
	
}

-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error{
	
	[theConnection release];
	[receivedData release];
	[theRequest release];
	
	NSLog(@"Connection failed. Error: %@ %@", [error localizedDescription], [[error userInfo] objectForKey:NSErrorFailingURLStringKey]);
	
	if(errorCallBack){
		[delegate performSelector:errorCallBack withObject:error];
	}
}

-(void)connectionDidFinishLoading:(NSURLConnection *)connection{
	
	if (delegate && callback){
		if([delegate respondsToSelector:[self callback]]){
			[delegate performSelector:[self callback] withObject:receivedData];
		}else{
			NSLog(@"No response from delegate!");
		}
	}
	[theConnection release];
	[theRequest release];
	[receivedData release];
}



Here's the .h:

@interface OnePageRequest : NSObject {
	
	NSString *username;
	NSString *password;
	NSMutableData *receivedData;
	NSURLRequest *theRequest;
	NSURLConnection *theConnection;
	id	delegate;
	SEL	callback;
	SEL errorCallBack;
	NSMutableArray *contactsArray;
}

@property (nonatomic,retain) NSString *username;
@property (nonatomic,retain) NSString *password;
@property (nonatomic,retain) NSMutableData *receivedData;
@property (nonatomic,retain) id delegate;
@property (nonatomic) SEL	callback;
@property (nonatomic) SEL	errorCallBack;
@property (nonatomic,retain) NSMutableArray *contactsArray;

-(void)friends_timeline:(id)requestDelegate requestSelector:(SEL)requestSelector;
-(void)request:(NSURL *) url;

@end


In the method: connectionDidFinishLoading, the following never gets executed:
[delegate performSelector:[self callback] withObject:receivedData];

Instead I get the message: "No response from delegate"


Anyone see what I'm doing wrong?! or what might be causing the problem?

Regards,
Fiona
