Reputation: 16793
I have one tabcontroller and it has two segments. One of them is UserInfo, another one is UserAvatar. Once user put into his info, then click on done button and go to mainview, or user could also choose his profile avatar and then click on click button and then could go to mainView. However, evethough I run by code with debug mode, it runs into done button, but in my userinfo view, delegeta method is not fired!
in my Main header file, I declared my protocol is as follow:
@protocol MyUserInfoAvatarViewControllerDelegate <NSObject>
@required
-(void)userInfoEditingDone:(id)sender;
@end
@protocol MyUserInfoSettingsViewControllerDelegate <NSObject>
@required
-(void)userInfoEditingDone:(id)sender;
@end
in my main.m file, my delegate method
- (void)userInfoEditingDone:(id)sender {
NSLog(@"Hello");
}
MyUserInfoAvatarViewController.h
#import <UIKit/UIKit.h>
#import "NEATMainViewController.h"
@interface UserInfoAvatarViewController : UIViewController <ThumbImageViewDelegate > {
id __unsafe_unretained flipDelegate;
}
@property (nonatomic,unsafe_unretained) id <MyUserInfoAvatarViewControllerDelegate>
flipDelegate; in the following responding in MyUserInfoAvatarViewController.m
- (IBAction)doneButtonPressed:(id)sender {
// Tell the root view to flip back over to the main view
[self.flipDelegate userInfoEditingDone:self];
}
MyUserInfoSettingsViewController.h
#import <UIKit/UIKit.h>
#import "NEATMainViewController.h"
@interface UserInfoSettingsViewController : UIViewController {
id __unsafe_unretained flipDelegate;
}
@property (nonatomic,unsafe_unretained) id <MyUserInfoSettingsViewControllerDelegate> flipDelegate;
in the following is not calling my delegate method.. MyUserInfoSettingsViewController.m
- (void)viewDidLoad {
[super viewDidLoad];
UIBarButtonItem *btn = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStyleBordered target:self action:@selector(done:)];
self.navigationItem.rightBarButtonItem = btn;
}
- (void)done:(id)sender {
// Tell the root view to flip back over to the main view
[self.flipDelegate userInfoEditingDone:self];
}
Upvotes: 1
Views: 517
Reputation: 38239
Check were you missed. It should like this for example say WeatherAPI
class :
@protocol WeatherAPIDelegate <NSObject>
-(void)weatherData:(NSMutableDictionary *)dictData;
@end
@interface WeatherAPI : NSObject
{
id <WeatherAPIDelegate>delegate;
}
@property(nonatomic,strong)id <WeatherAPIDelegate> delegate;
@end
Call delegate
method like this in WeatherAPI
:
[delegate weatherData:dictWeatherInfo];
Now implement in say ViewController
:
@interface ViewController : UIViewController<WeatherAPIDelegate>
{
}
Implement WeatherAPIDelegate
method in ViewController
:
#pragma mark -
#pragma mark WeatherAPIDelegate Method
-(void)weatherData:(NSMutableDictionary *)dictData
{
}
When intializing WeatherAPI
in ViewController
WeatherAPI *objWeatherAPI = [[WeatherAPI alloc]init];
[objWeatherAPI setDelegate:self];
Upvotes: 1
Reputation: 39988
It's because you flipDelegate
is nil
and more over you have defined delegate method in main.m
which I think doesn't have any class which implements your protocol.
Upvotes: 1