ios delegate 用法

来源:互联网 发布:网络电视盒什么牌子好 编辑:程序博客网 时间:2024/05/23 22:40

主要涉及到两个文件。

第一个文件,我称之为定义delegate的文件,要做的事:

1. 在BorderDetectionViewController.h中做两件事

(1)

@protocol BorderDetectionViewControllerDelegate <NSObject>
- (void)dismissBorderDetectionView;
@end

(2)

 @property (nonatomic, assign) id<BorderDetectionViewControllerDelegate> delegate;

2.在BorderDetectionViewController.m中做两件事
(1)
@synthesize delegate;
(2)
[self.delegate dismissBorderDetectionView];
 
在第二个文件中,我称之为应用文件,要做的事:
1. 在MainTabViewController.h中做两件事:
(1)
#import "BorderDetectionViewController.h"
(2)
在interface后面加上<BorderDetectionViewControllerDelegate>
2. 在MainTabViewController.m中做两件事:
(1)在要present borderView时,设置borderViewController.delegate = self;
(2)实现该delegate函数
- (void)dismissBorderDetectionView
{
   [self dismissModalViewControllerAnimated:YES];
}
1 1