首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >是否未显示rightbarbuttonitem项?

是否未显示rightbarbuttonitem项?
EN

Stack Overflow用户
提问于 2012-07-07 07:09:34
回答 2查看 933关注 0票数 1

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

出于某种奇怪的原因,我的左栏按钮项目正在显示,但我的右栏按钮项目从来没有弹出!这是我的代码

代码语言:javascript
复制
    -(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方法中,我有以下内容:

代码语言:javascript
复制
[self barButton2];
[self barButton];

该操作完成后,我确实收到了我的NSLog方法。有人知道为什么会这样吗?左栏按钮总是会出现,如果我把第一个栏按钮改成右栏按钮项,把barbutton2改成左栏按钮项,然后改一下CGRect坐标,它就能用了,这就是我现在用来让它工作的地方,但为什么会这样呢?提前谢谢。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-07-07 07:29:13

您看不到右按钮,因为您将它绘制在屏幕之外。

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

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

代码语言:javascript
复制
button2.frame= CGRectMake(0.0, 5.0, image2.size.width, image2.size.height);
票数 2
EN

Stack Overflow用户

发布于 2012-07-07 07:14:01

您似乎在为每个操作创建一个新视图,并添加一个按钮。所以,你永远不会同时看到这两个按钮。您需要在两个操作中访问相同的视图,以确保添加了两个按钮子视图。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11370755

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档