文件:PeopleLinkEditViewController.h
@protocol PeopleLinkEditViewControllerDelegate<NSObject>
@optional
-(void)headerInfoEditFinish;
@end
@interface PeopleLinkEditViewController : UITableViewController
{
id<PeopleLinkEditViewControllerDelegate> delegate;
}
@property (nonatomic, retain) id<PeopleLinkEditViewControllerDelegate> delegate;
-(IBAction)doneEdit:(id)sender;
@end
文件:PeopleLinkEditViewController.m
@implementation PeopleLinkEditViewController
...
@synthesize delegate = _delegate;
...
- (void)viewDidLoad
{
...
headerView = [[PeopleLinkHeaderView alloc] initWithFrame:CGRectMake(0, 0, 320, 286)
passData:headerDic];
...
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
if(section == 0)
{
return headerView;
}
return nil;
}
-(IBAction)doneEdit:(id)sender
{
if ([delegate respondsToSelector:@selector(headerInfoEditFinish)])
{
NSLog(@"%d", __LINE__);
[delegate headerInfoEditFinish];
}
}
@end
文件:PeopleLinkHeaderView.h
#import "PeopleLinkEditViewController.h"
@interface PeopleLinkHeaderView : UIView<PeopleLinkEditViewControllerDelegate>
{
}
@end
文件:PeopleLinkHeaderView.m
@interface PeopleLinkHeaderView()
@property (nonatomic, retain) PeopleLinkEditViewController *edit;
@end
@implementation PeopleLinkHeaderView
- (id)initWithFrame:(CGRect)frame passData:(NSDictionary *)data
{
UIStoryboard* sb = [UIStoryboard storyboardWithName:@"MainStoryboard"
bundle:nil];
PeopleLinkEditViewController *edit = [sb instantiateViewControllerWithIdentifier:@"PeopleLinkEditController"];
edit.editDelegate = self;
}
-(void)headerInfoEditFinish
{
[baseInfo setValue:baseInfoValue forKey:@"value"];
[dataPass writeHeaderValueToPlist:baseInfo];
}
无法调用委托的方法。当我调试它时,我发现在editcontroller中委托是零。和 editcontroller 由情节提要创建。Headerview 是编辑控制器的子视图。