这可能很简单,但我被困住了!
基本上我有一个父子视图控制器,我试图将数据从子节点传递给父节点。
//子VC接口
@protocol ANSearchGetawayFilterDelegate
-(void)selectedCell:(NSString *)cellTitle;
@end
@interface ANSearchGetawayFilterViewController : UIViewController <UITableViewDelegate, UITableViewDataSource, UISearchBarDelegate>
{
NSString* cellTitle;
}
@property (nonatomic, assign) id<ANSearchGetawayFilterDelegate> delegate;
@end
//子VC实现
@implementation ANSearchGetawayFilterViewController
@synthesize delegate = _delegate;
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath];
cellTitle = selectedCell.textLabel.text;
[[self delegate] selectedCell:cellTitle];
[self dismissModalViewControllerAnimated:YES];
}
//父VC接口
#import "ANSearchGetawayFilterViewController.h"
@interface ANGetawayFilterViewController : UIViewController <ANSearchGetawayFilterDelegate>
{
NSString* _cellText;
}
//父VC实现
- (id)initWithNibName:(NSString*)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self)
{
// Custom initialization
ANSearchGetawayFilterViewController *search = [[ANSearchGetawayFilterViewController alloc] init];
search.delegate = self;
}
return self;
}
//delegate method
-(void)selectedCell:(NSString *)cellTitle
{
_cellText = cellTitle;
NSLog(@"cell text %@", _cellText);
}
委托方法永远不会被调用,什么时候 NSLog _cellText 其他地方它出现为空......我做错了什么?谢谢!