财产代表'在类型' UIViewController上找不到对象*'

时间:2014-04-01 18:55:06

标签: ios objective-c uiviewcontroller

当我运行项目时,我收到以下错误,在行secView.delegate=self;中指出 我该如何解决上述问题?谢谢!

  

在'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];


              }

}

2 个答案:

答案 0 :(得分:3)

当您声明secView时,您将其定义为UIViewController *secView - 即普通UIViewController。因此,就编译器而言,它没有任何自定义属性。

您需要将其声明为它在运行时的特定类类型:

BookmarkViewController *secView = ...;

答案 1 :(得分:1)

您需要进一步确定secView对象的范围。 UIViewController未声明委托属性,但您的协议确实如此。如果您确定视图控制器将实现该协议,请尝试以下操作:

UIViewController<secondViewControllerDelegate> *secView = [st instantiateViewControllerWithIdentifier:@"bookmarkViewController"];