注:我可以通過在我的barbutton和barbutton2方法中將leftbarbuttonitem切換到rightbarbutton項目來實現此目的。我只是想知道爲什麼它不能正常工作!rightbarbuttonitem沒有顯示出來?
出於某種奇怪的原因,我的左巴鈕釦圖案正在顯示,但我的右巴鈕釦圖案永遠不會彈出!這裏是我的代碼
-(void)barButton {
image = [UIImage imageNamed:@"BBut.png"];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setBackgroundImage: [image stretchableImageWithLeftCapWidth:7.0 topCapHeight:0.0] forState:UIControlStateNormal];
[button setBackgroundImage: [[UIImage imageNamed: @"BBut.png"] stretchableImageWithLeftCapWidth:7.0 topCapHeight:0.0] forState:UIControlStateHighlighted];
[button addTarget:self action:@selector(showlocations:) forControlEvents:UIControlEventTouchUpInside];
button.frame= CGRectMake(3.0, 0.0, image.size.width+1, image.size.height+0);
UIView *v=[[UIView alloc] initWithFrame:CGRectMake(3.0, 0.0, image.size.width+1, image.size.height) ];
[v addSubview:button];
UIBarButtonItem *modal = [[UIBarButtonItem alloc] initWithCustomView:v];
self.navigation.leftBarButtonItem = modal;
-(void)barButton2 {
image2 = [UIImage imageNamed:@"Refresh.png"];
UIButton *button2 = [UIButton buttonWithType:UIButtonTypeCustom];
[button2 setBackgroundImage: [image2 stretchableImageWithLeftCapWidth:0.0 topCapHeight:0.0] forState:UIControlStateNormal];
[button2 setBackgroundImage: [[UIImage imageNamed: @"Refresh.png"] stretchableImageWithLeftCapWidth:0.0 topCapHeight:0.0] forState:UIControlStateHighlighted];
// [button2 addTarget:self action:@selector(viewDidLoad) forControlEvents:UIControlEventTouchUpInside];
button2.frame= CGRectMake(281.0, 5.0, image2.size.width, image2.size.height);
UIView *v2=[[UIView alloc] initWithFrame:CGRectMake(281.0, 5.0, image2.size.width, image2.size.height) ];
[v2 addSubview:button2];
UIBarButtonItem *refresh = [[UIBarButtonItem alloc] initWithCustomView:v2]; self.navigation.rightBarButtonItem = refresh;
NSLog(@"THE ACTION HAS BEEN RECIEVED!"); }
在我viewDidLoad方法中,我有這樣的:
[self barButton2];
[self barButton];
行動確實經歷,我也接受我的NSLog的方法。有誰知道爲什麼會發生這種情況?左欄按鈕總是顯示出來,如果我將第一個barbutton更改爲rightbarbuttonitem,並將barbutton2更改爲leftbarbutton項,然後更改CGRect座標系,它就可以工作,這就是我現在正在使用它來使其工作,但爲什麼會發生這種情況?提前致謝。
謝謝!就是這樣!我不知道爲什麼我明白它會在x = 281的原始視圖中。這讓我有點瘋狂!再次感謝你! – sridvijay 2012-07-06 23:33:04