注:barbuttonメソッドとbarbutton2メソッドでleftbarbuttonitemをrightbarbutton itemに切り替えることで、これを機能させることができます。なぜ正常に動作しないのか知りたいだけです!
奇妙な理由で、左のbarbuttonitemが表示されていますが、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メソッドを受け取ります。なぜこれが起こっているのか誰かが知っていますか?左バーボタンは常に表示されます。最初のバーボタンをrightbarbuttonitemに変更し、barbutton2をleftbarbuttonアイテムに変更してから、CGRect座標を変更すると、機能します。これを使用して、機能させることができます。しかし、なぜこれが起こっているのですか?前もって感謝します。