2015-06-29 69 views
1

在我MainMainViewController我創造了新的UIView(ContentView)。我設置了調用方法來定位錯誤

DetailViewController *detailView = 
    [[DetailViewController alloc] initWithObject:paAnnotation]; 
detailView.view.frame = CGRectMake(0, 
            0, 
            [self getWidthOfScreen], 
            [self getWidthOfScreen]); 
[contentView addSubview:detailView.view]; 

它工作正常,但在我的DetailViewController中,我創建了UIButton並設置了目標操作。但是當我點擊按鈕時,它崩潰並顯示錯誤。你能告訴我哪裏可以解決問題嗎?

- (id)initWithObject:paAnnotation { 

    if ((self = [super init])) { 
     self.annotation = paAnnotation; 
    } 

    return self; 
}  

- (void)viewDidAppear:(BOOL)animated { 

     UIButton *closeButton = [[UIButton alloc] initWithFrame:CGRectMake(50, 50, 50, 50)]; 
     closeButton.backgroundColor = [UIColor redColor]; 
     [closeButton addTarget:self 
         action:@selector(closeContent) 
       forControlEvents:UIControlEventTouchUpInside]; 
     [self.view addSubview:closeButton]; 

} 

- (void)closeContent { 
    NSLog(@"Test"); 
} 

錯誤:

-[GEOVectorTile closeContent]: unrecognized selector sent to instance 0x19d0a1e0 
+0

你tryied設置裏面'viewDidLoad'按鈕? –

+0

是的,我試過,但沒有工作相同的錯誤。 –

回答

2

在你MainMainViewController,嘗試當你初始化它保留您的DetailView。或者在MainMainViewController中創建detailView作爲retain屬性,然後使用它。

+0

我試着設置'@財產(非原子,保留)的UIView *內容查看;'但現在點擊後,顯示我錯誤'EXC_BAD_ACCESS' –

+1

嘗試使用@屬性(非原子,保留)DetailViewController *的DetailView –

+0

它的工作原理謝謝! –