0

在 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];
    }
}

使用情节提要时,我如何为此发出 target:self action:@selector 语句

4

1 回答 1

1

检查这个问题

 -(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];
}

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

于 2013-08-03T12:09:02.393 回答