【问题标题】:UIBarButtonItem in UIStoryboard shows error in action methodUIStoryboard 中的 UIBarButtonItem 在操作方法中显示错误
【发布时间】:2013-08-03 11:33:18
【问题描述】:

在 UIstoryboard 中添加 UIBarButtonItem 并声明 UIBarbuttonitem 的操作方法。

在为动作方法编写代码时,在这一行显示错误

[_bookmarkbtn setBookmarkState:NO];

在这一行

[_bookmarkbtn setBookmarkState:YES];

在下面的 UIBarButtonItem Action 方法中

uibarbuttonitem 没有可见的@interface 声明选择器“setBookmarkState”

- (IBAction)bookmarkAction:(id)sender {

    currentIndex = [modelArray indexOfObject:contentViewController.page];

    if ([contentViewController.bookmarks containsIndex:currentIndex]) // Remove bookmark
    {
        [_bookmarkbtn setBookmarkState:NO]; [contentViewController.bookmarks removeIndex:currentIndex];
    }
    else // Add the bookmarked page index to the bookmarks set
    {
        [_bookmarkbtn setBookmarkState:YES]; [contentViewController.bookmarks addIndex:currentIndex];
    }
}

使用情节提要时,我如何为此发出目标:自我操作:@selector 声明

【问题讨论】:

  • 检查你的类 UIBarbuttonitem 在接口方法 setBookmarkState: (或属性 bookmarkState)。
  • 我在 UIBarButtonItem 的文档中找不到任何名为 bookMarkState 的属性...

标签: iphone objective-c ios6


【解决方案1】:

查看question

 -(IBAction) btnOpenImage_Clicked:(id)sender{

//1. IF buttons are UIBarButtonItem then use bellow code
              // This bellow line for Change the action(Target)
             [rightNavButton1 setAction:@selector(rightNavButton2_Clicked)]; 

             //This bellow line For Change  the Title
             [rightNavButton1 setTitle:@"rightNavButton2_Clicked"]; 

//OR 2. IF buttons are UIButton then use bellow code

            // This bellow line for Change the action(Target)
            [rightNavButton1 addTarget:self action:@selector(rightNavButton2_Clicked) forControlEvents:UIControlEventTouchUpInside];

            //This bellow line For Change  the Title
            [rightNavButton1 setTitle: @"rightNavButton2" forState: UIControlStateNormal];
}

它可能会帮助你。试一试。

【讨论】:

  • 谢谢,但这并没有帮助。而是通过这样写来修复它 _bookmarkbtn.enabled = NO;和 _bookmarkbtn.enabled = YES;
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-04-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多