【发布时间】:2012-05-29 22:30:59
【问题描述】:
这可能很简单,但我被卡住了!
基本上我有一个父子视图控制器,我试图将数据从子视图传递给父视图。
//子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 其他地方出现为空......我做错了什么?谢谢!
【问题讨论】:
-
你能展示你实际展示 childViewController 的位置吗?
-
确定
- (BOOL)textFieldShouldBeginEditing:(UITextField*)textField { BOOL shouldBeginEditing = YES; NSLog(@"text field should begin editing"); ANSearchGetawayFilterViewController *myANSearchGetawayFilterViewController = [[[ANSearchGetawayFilterViewController alloc] init] autorelease]; [self presentModalViewController:myANSearchGetawayFilterViewController animated:YES]; [self closeAllPickers]; return shouldBeginEditing; }
标签: iphone ios uitableview delegates