2012-09-20 111 views
0

我正在以編程方式創建一些barbutton項目,但第一個按鈕點擊選擇器沒有被調用。我在viewDidLoad中下面的代碼現在:UIBarButtonItem沒有響應

[super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 
    // self.navigationItem.leftBarButtonItem = self.editButtonItem; 


    _defaultBarColor = self.navigationController.navigationBar.tintColor; 
    [self loadPreferences]; 


    self.spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; 
    self.btnSpinner = [[UIBarButtonItem alloc] initWithCustomView:self.spinner]; 

    self.btnRefresh = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(refreshPressed:)]; 

    self.lblLastUpdate = [[UIBarButtonItem alloc] initWithTitle:@" " style:UIBarButtonItemStylePlain target:nil action:nil]; 
    [self.lblLastUpdate setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont boldSystemFontOfSize:13], UITextAttributeFont,nil] forState:UIControlStateNormal]; 

    self.flexibleSpace = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]; 
     self.toolbarItems = [NSArray arrayWithObjects:self.btnRefresh,self.flexibleSpace,self.lblLastUpdate,self.flexibleSpace, nil]; 



    self.detailViewController = (DetailViewController *)[[self.splitViewController.viewControllers lastObject] topViewController]; 


    [self loadData]; 

我發現到目前爲止是,如果我設置的標籤選擇器(在工具欄第二項)的第一個項目的選擇,那麼,第一項選擇器被調用。

任何想法?

回答

0

你分配barbutton,但你沒有設置barButton的框架。

爲barButton分配設置框後。

btnSpinner.frame=CGRectMake(10,10,70,40); 
+0

我自己解決了這個問題。至少可以說這是一個奇怪的問題。我發現如果第二個元素中的文本更長,第一個Barbutton的動作就不會被調用。縮短文本後,它開始正常工作。感謝您的輸入。 – userx