Reputation:
my protocol method isn't called ... i'm new in obj-c programming ...
i have a header file for protocol
..........CanUpdateTime.h .....................
#import <Foundation/Foundation.h>
@protocol CanUpdateTime
-(BOOL)canUpdateTime;
@end
..............class interface where i declare my delegate variable and set it's property ..............
#import <UIKit/UIKit.h>
#import "Currency.h"
#import "CanUpdateTime.h"
@protocol CanUpdateTime;
@interface CurrencyViewController : UIViewController <UITableViewDelegate, UITableViewDataSource > {
Currency *currency;
UILabel *dayMonthYear;
id <CanUpdateTime> update;
}
@property (nonatomic, retain) Currency *currency;
@property (nonatomic, retain) IBOutlet UILabel *dayMonthYear;
@property (nonatomic, assign) id <CanUpdateTime> update;
........ implementation file ..............
-(void)viewDidLoad {
[[self update]canUpdateTime];
}
..... the class where i placed the definition of delegate method ...
@interface ExchangeRatesProvider : NSObject <NSXMLParserDelegate,CanUpdateTime> {
and so on ...
}
.... implementation file ..................
-(BOOL)canUpdateTime {
NSLog (@"ok");
return YES;
}
but nothing happens ... i tried to pass to de update(delegate) respondsToSelector method but nothing happens ... my delegate method doesnt respond ... any ideas ... ???
p.s. sorry for my english ... thanks for attention ...
Upvotes: 1
Views: 137
Reputation: 1117
My best guess is that your update variable has never been filled with an ExchangeRatesProvider instance.
At some point in your code and before calling [[self update] canUpdateTime]
you need to put an object that conforms to your protocol in the variable.
Looking at your code I think the missing line here is :
ExchangeRatesProvider* provider = [[ExchangeRatesProvider alloc] init];
[[self setUpdate:provider];
These lines can be at the very beginning of viewDidLoad or in the init method.
Don't forget to release the provider when you're done with it with a [self setUpdate:nil]
Upvotes: 0
Reputation: 26400
In ExchangeRatesProvider
you should set the delegate for CurrencyViewController
as
currencyController.update = self;
where currencyController
is an instance of CurrencyViewController
Upvotes: 1