我在运行项目时出现以下错误,在行中指示secView.delegate=self;
我该如何解决上述问题?谢谢!在'UIViewController *'类型上找不到属性'委托'对象
属性 '代理' 的对象不是类型 '的UIViewController *'
myViewController.h
@interface myViewController : UIViewController <UITextFieldDelegate,UIAlertViewDelegate,secondViewControllerDelegate>
- (IBAction)popBookmarkTable:(id)sender;
myViewController.m
- (IBAction)popBookmarkTable:(id)sender {
UIStoryboard *st = [UIStoryboard storyboardWithName:[[NSBundle mainBundle].infoDictionary objectForKey:@"UIMainStoryboardFile"] bundle:[NSBundle mainBundle]];
UIViewController *secView = [st instantiateViewControllerWithIdentifier:@"bookmarkViewController"];
[self presentViewController:secView animated:YES completion:nil];
secView.delegate=self;
}
- (void)passData:(NSString *)data
{
_addressBar.text=data;
}
发现bookmarkViewController.h
@protocol secondViewControllerDelegate <NSObject>
@required
- (void)passData:(NSString *)data;
@end
@property (nonatomic, weak) id<secondViewControllerDelegate> delegate;
@property (nonatomic,strong) NSString *a;
@end
bookmarkViewController.m
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell * cell = [tableView cellForRowAtIndexPath:indexPath];
if ([indexPath row]==0) {
_a=(NSString *)cell.textLabel.text;
[_delegate passData:_a];
[self dismissViewControllerAnimated:YES completion:nil];
}
}
真棒,它的工作就像一个魅力。非常感谢你! – floyddd
只需替换 UIViewController * menuVC = [[MenuViewController alloc] initWithNibName:@“MenuViewController”bundle:nil]; 在 MenuViewController * menuVC = [[MenuViewController alloc] initWithNibName:@“MenuViewController”bundle:nil]; – dip