gpt4 book ai didi

iphone - rightbarbuttonitem 没有显示?

转载 作者:行者123 更新时间:2023-11-29 11:11:30 27 4
gpt4 key购买 nike

注意:我可以通过在我的 barbutton 和 barbutton2 方法中将 leftbarbuttonitem 切换为 rightbarbutton item 来实现它。我只是想知道为什么它不能正常工作!

由于某些奇怪的原因,我的 leftbarbuttonitem 正在显示,但我的 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 方法。有谁知道为什么会这样? Left Bar Button 始终显示,如果我将第一个 barbutton 更改为 rightbarbuttonitem 并将 barbutton2 更改为 leftbarbutton item,然后更改 CGRect 坐标,它会起作用,这就是我现在正在使用的方法,但为什么会这样呢?提前致谢。

最佳答案

您没有看到右侧按钮,因为您将其绘制在屏幕之外。

button2 X 坐标设置为 281.0,其父 View X 坐标也设置为 281.0。因此,您的按钮在 x = 562 中,这意味着它在屏幕之外。

将你的 button2 X 坐标设置为 0,看看是否有帮助:

button2.frame= CGRectMake(0.0, 5.0, image2.size.width, image2.size.height);

关于iphone - rightbarbuttonitem 没有显示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11370755/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com