2012-05-08 24 views
0

我試圖刪除從NSNotification添加的UIView。當我按下「完成」按鈕時,應用程序應該刪除screen3,但它不起作用。有什麼建議麼? 在這裏你的代碼:從註冊了UIButton元素的IBAction中刪除UIView

- (void) mostrarCompra:(NSNotification *) notification 
{ 
    [self buyView:self]; 
} 

- (void)buyView:(id)sender 
{ 
    screen3 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width,    self.view.bounds.size.height)]; 
    screen3.backgroundColor= [UIColor grayColor]; 

    UIToolbar* tabBar = [UIToolbar new]; 
    tabBar.barStyle = UIBarStyleDefault; 
    [tabBar sizeToFit]; 
    [tabBar setFrame:CGRectMake(0,0,self.view.bounds.size.width,60)];  
    UIBarButtonItem *atras = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self action:@selector(returnBuy:)]; 

    [tabBar setItems:[NSArray arrayWithObjects:atras,nil]]; 

    [screen3 addSubview:tabBar]; 

    [superwindow addSubview:screen3]; 
} 

- (IBAction)returnBuy:(id)sender{ 

    [screen3 removeFromSuperview]; 
} 

謝謝。

+1

你確定方法returnBuy:被調用嗎? – yehnan

+0

在** returnBuy * –

回答

1

使用的NSLog剛剛之前加入SCREEN3作爲子圖和從上海華作爲

的NSLog去除(@ 「%@」,畫面3);

如果輸出是對兩個地方的同一位置的引用,那麼還有其他的prblm,但它的指針值是不同的,如0x324fa和0xa214c,那麼您在分配或更改screen3的值期間添加和刪​​除視圖。告訴我你是否得到了這種情況。

+0

中放置斷點謝謝!!! NSNotification被打電話一次以上,解決:) – Gustavo

+0

歡迎你親愛的 – Saad