2014-01-23 35 views
1

我想使一個工具欄出現(工作),一旦出現我想單擊完成按鈕並關閉工具欄(不起作用)。我不知道如何去做這件事,我想通過刪除pickerview它會工作。我認爲最大的問題是我的取消率方法沒有被調用。iOS:我有這個UIToolBar,我試圖擺脫當一個按鈕被點擊

 pickerView = [[UIView alloc]initWithFrame:CGRectMake(0, 300, 180, 260)]; 

    rateToolbar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)]; 
    rateToolbar.barStyle = UIBarStyleBlackTranslucent; 
    rateToolbar.items = [NSArray arrayWithObjects: 
         [[UIBarButtonItem alloc]initWithTitle:@"Done" style:UIBarButtonItemStyleBordered target:self action:@selector(cancelRate)], 
         [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil], 

         nil]; 
    [rateToolbar sizeToFit]; 

    [pickerView addSubview:rateToolbar]; 
    [self.view addSubview:pickerView]; 

    -(void)cancelRate{ 
    [pickerView removeFromSuperview]; 
    } 
+0

你爲什麼不把一個的NSLog(@ 「被稱爲」);在你的cancelRate方法中,並檢查它是否被調用? – sbarow

+0

我做了,它不被稱爲,但我不知道爲什麼。 – user3228760

+0

我會建議更新你的問題,因爲你的問題沒有被調用的方法。 http://stackoverflow.com/questions/2796438/uibarbuttonitem-target-action-not-working – sbarow

回答

0

這是我要做的事..

//PUT THIS CODE ON THE VIEWDIDLOAD EVENT 
UIBarButtonItem *button2 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(pressReloadButton)]; 
     self.navigationItem.rightBarButtonItem = button2; 

//THIS IS THE METHOD THAT IS CALLED 
- (void)pressReloadButton{ 
    self.spinner.hidden = NO; 
    [self.spinner startAnimating]; 
    [self refresh]; 
} 

希望它有助於.. GL HF

相關問題