У меня есть проект, в котором SwitchViewController является корневым контроллером
Он загружает viewcontroller2 в некотором состоянии,
viewcontroller2 загрузить modalviewcontroller1 в некотором состоянии.
В modelviewcontroller1 (точка останова 1) есть одна функция okButtonPressed,
Я надеюсь, что он может уведомить viewcontroller2 и вызвать функцию 'dosomething' (// точка останова 2)
Итак, я установил протокол, все viewcontroller (switchviewcontroller, viewcontroller2, modalviewcontroller1)
содержать протокол
Я установил точку останова1 и точку останова2, как показано ниже.
Нет сообщений об ошибках, но остановка на точке останова 2 не выполнена, «dosomething» не было выполнено.
Приветствую любой комментарий
Спасибо
InterDev
//----------------------------------------------source codes
//myprotocol.h
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@class Myprotocol;
@protocol MyprotocolDelegate <NSObject>
@optional
- (void)function1 ;
@end
//-----------------------------------
@interface Myprotocol : NSObject {
id <MyprotocolDelegate> delegate;
}
@property (nonatomic, assign) id <MyprotocolDelegate> delegate;
@end
//myprotocol.m
#import "myprotocol.h"
@implementation Myprotocol
@synthesize delegate;
- (void)dealloc {
[super dealloc];
}
@end
//"ModalViewController1.h"
#import <UIKit/UIKit.h>
#import "myprotocol.h"
@interface ModalViewController1 : UIViewController <MyprotocolDelegate> {
id<MyprotocolDelegate> delegate;
}
@property (nonatomic, assign) id<MyprotocolDelegate> delegate;
- (IBAction)okButtonPressed:(id)sender;
@end
//"ModalViewController1.m"
#import "ModalViewController1.h"
@implementation ModalViewController1
@synthesize delegate;
- (IBAction)okButtonPressed:(id)sender;
{
[delegate function1];//breakpoint 1
[self.view removeFromSuperview];
}
//------ViewController2.h"
#import <UIKit/UIKit.h>
#import "myprotocol.h"
@class ModalViewController1 ;
@interface ViewController2 : UIViewController <MyprotocolDelegate>{
ModalViewController1 *vModalViewController1;
id<MyprotocolDelegate> delegate;
}
@property (nonatomic, assign) id<MyprotocolDelegate> delegate;
@property (retain,nonatomic) ModalViewController1 *vModalViewController1;
@end
//----ViewController2.m"--------------
#import "ViewController2.h"
#import "ModalViewController1.h"
@synthesize delegate;
- (void)function1;
{
[self dosomething];//breakpoint 2
}
//SwitchViewController.h
#import <UIKit/UIKit.h>
#import "myprotocol.h"
@class ViewController2;
@class ModalViewController1 ;
@interface SwitchViewController : UIViewController <MyprotocolDelegate> {
ViewController2 *vViewController2;
}
@property (retain,nonatomic) ViewController2 *vViewController2;
@end
//in SwitchViewController.m
ViewController2 *vvViewController2=[[ViewController2 alloc]
initWithNibName:@"View2" bundle:nil];
self.vViewController2=vvViewController2;
[vvViewController2 release];
[self.vViewController2 setDelegate:self];