2011-12-01 32 views
0

我正在加載mapview。我在視圖的底部工具欄中創建了一個barbutton,並將其標識符設置爲pagecurl。正如所料,帶有頁面捲曲圖標的barbutton被加載。在此mapview中,我將移至另一個視圖,方法是單擊mapview中的註釋。然後我返回到地圖視圖。那時我的pagecurl barbutton圖標(pagecurl圖標)沒有顯示,我的barbutton寬度也減少了。我無法弄清楚問題所在。工具欄barbutton圖標(pagecurl)未加載

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    if(isSingleContactSelected) 
    { 
     [self.navigationController.navigationBar setBarStyle:UIBarStyleDefault]; 
     self.navigationItem.leftBarButtonItem = self.cancelButton ; 
     [self.cancelButton setTarget:self]; 
     [self.cancelButton setAction:@selector(onClose:)]; 

     [addressFieldSearchBar setFrame:CGRectMake(66, 0, 256, 44)]; 
     addressFieldSearchBar.delegate =self; 

     [self.navigationController.navigationBar setBarStyle:UIBarStyleDefault]; 
     [self.navigationController.navigationBar addSubview:addressFieldSearchBar]; 

     [searchDirectionSegmentedControl addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged]; 
     UIBarButtonItem *searchDirectionSegmentedButton = [[UIBarButtonItem alloc] initWithCustomView:searchDirectionSegmentedControl]; 

     flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]; 
     NSArray *toolbarItems = [NSArray arrayWithObjects: compassButton , flexibleSpace, searchDirectionSegmentedButton, flexibleSpace, pageButton, nil]; 
     [self setToolbarItems:toolbarItems]; 

     self.navigationController.toolbarHidden = NO; 
     [compassButton release]; 
     [pageButton release]; 
     [searchDirectionSegmentedControl release]; 

     mapView = [[MKMapView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)]; 
     mapView.delegate=self; 

     [self.view addSubview:mapView]; 
    } 
} 

- (void)viewDidUnload{ 
    [super viewDidUnload];  
} 

-(void) viewWillAppear:(BOOL)animated{ 
    if(isSingleContactSelected){ 
     [self.navigationController.navigationBar setHidden:NO]; 
     [self.navigationController.toolbar setHidden:NO]; 
     [self.navigationController.toolbar setBarStyle:UIBarStyleDefault]; 
     [self.addressFieldSearchBar setHidden:NO]; 
    } 
} 

-(void) viewWillDisappear:(BOOL)animated{ 
    if(isSingleContactSelected){ 
     [self.addressFieldSearchBar setHidden:YES]; 
     [self.navigationController.toolbar setHidden:YES]; 
    } 
} 
+0

一些代碼將是有益的。 – visakh7

+0

我已經添加了代碼。我通過xib文件設置了barbutton的屬性。 –

+0

在'viewWillAppear:'方法中移動您的代碼以設置工具欄。 –

回答

1

儘管它很長,但它可能與你的出現和消失方法中的setHidden調用有關。

[self.navigationController.toolbar setHidden:YES]; 
[self.navigationController.toolbar setHidden:NO]; 

的最好辦法做到這一點使用UIViewController的 「-setHidesBottomBarWhenPushed:」 方法。

也許嘗試一些的NSLog()在-viewWillAppear:

// If pageButton is an instance variable 
NSLog(@"%@",pageButton); 

// Enumerate through all toolbar items. 
// Check to see if NSLog output differs after pushing/popping this view controller. 
for (UIBarButtonItem *item in [self.navigationController.toolbar.items]) 
{ 
    NSLog(@"%@",item); 
} 
+0

同樣的問題又出現了,這次我不能處理它。 –

0

setHidesBottomBarWhenPushed方法在這種情況下伎倆。