1

这是我的代码:

@interface RootViewController : UIViewController{

}
-(IBAction)btnDetail1_Clicked:(id)sender;
@end



@implementation RootViewController

-(IBAction)btnDetail1_Clicked:(id)sender{
    DetailViewController1 *mvcr = [[DetailViewController1 alloc] initWithNibName:@"DetailViewController1" bundle:nil];
    [mvcr setDelegate:self];
    [self.navigationController pushViewController:mvcr animated:YES];
    [mvcr release];
}
@end



@protocol NotifySubclass
@optional
-(void) serviceCall_done;
@end

@interface MasterViewController : UIViewController{
     id<NotifySubclass> delegate;
}
@property (retain) id delegate;
-(void) initCallService;
@end




@implementation MasterViewController
@synthesize delegate;

-(void) initCallService{
    "My some other code is here."
    [self performSelector:@selector(startLoading) withObject:nil afterDelay:5];
}

-(void) startLoading{
    "My some other code is here."
    [self performSelectorOnMainThread:@selector(loadComplete) withObject:nil waitUntilDone:YES];
}

-(void) loadComplete{
    "I want to call DetailViewController1's "serviceCall_done" method from here.
     [delegate serviceCall_done];
}
@end



@interface DetailViewController1 : MasterViewController <NotifySubclass>{

}
@end




@implementation DetailViewController1
- (void)viewDidLoad{
    [self initCallService];
}

-(void) serviceCall_done{

}
@end

我想从的方法中调用DetailViewController1的方法。serviceCall_doneloadCompeteMasterViewController

我曾尝试创建协议,但没有得到我在调用时必须编写协议的确切DetailViewController1位置RootViewController

任何人都可以指导我吗?

4

2 回答 2

2

在中添加方法MasterViewController

-(void) serviceCall_done{
    //in this method you do nothing.
}

调整

-(void) loadComplete{
    [self serviceCall_done];
}

然后,在DetailViewController1覆盖这个方法serviceCall_done

-(void) serviceCall_done{
    //Add code
}
于 2013-03-22T09:14:26.990 回答
0

您可以为此发布通知使用 NSNotificationCenter 并在所有 3 个详细信息类中添加观察者。阅读一些关于 NSNotificationCenter 的教程。

这里有一些教程

教程 1

教程 2

教程 3

于 2013-03-22T09:06:24.427 回答