2014-04-01 1 views
0

프로젝트를 실행할 때 다음 오류가 나타납니다. secView.delegate=self;
위의 문제를 어떻게 해결할 수 있습니까? 감사!'UIViewController *'유형의 'delegate'객체가 없습니다.

재산권 '위임'객체는 bookmarkViewController.h

유형 '의 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; 

    } 

를 찾을 수 없습니다즉 일반 UIViewController - 당신이 secView를 선언하면

@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]; 


       } 

} 

답변

3

, 당신은 UIViewController *secView로 정의한다. 따라서 컴파일러에 관한 한 사용자 지정 속성이 없습니다.

BookmarkViewController *secView = ...; 
+0

정말 멋지다. 고마워요! – floyddd

+0

그냥 바꾸기 UIViewController * menuVC = [[MenuViewController alloc] initWithNibName : @ "MenuViewController"번들 : nil]; 에 MenuViewController * menuVC = [[MenuViewController alloc] initWithNibName : @ "MenuViewController"번들 : nil]; – dip

1

당신은 범위 당신의 secView 객체를 촉진해야합니다

귀하는 런타임에있을 것입니다 특정 클래스 형식으로 선언해야합니다. UIViewController은 대리자 속성을 선언하지 않지만 프로토콜은 않습니다. 보기 컨트롤러가 해당 프로토콜을 구현한다고 확신하는 경우 다음을 시도해보십시오.

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