0

我试图将 barbuttonitem 添加到 xcode proj 中,最后使用视图控制器显示它并将代码放在视图中确实加载部分,但我无法连接操作......我一直使用界面构建器和 IBOutlets 但那不是一个选项,因为必须以编程方式放入此导航控制器才能使标签栏控制器工作

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    //add navbar buttons progamatically b/c nothing to use in xibs...
    UIBarButtonItem * popbutt = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(apopbuttonPressed:)];

    UINavigationItem * navigItem = [[UINavigationItem alloc]initWithTitle:@"Scribbler"];
    navigItem.rightBarButtonItem = popbutt;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

这是我第一次尝试在不使用 IBOutlet 和界面构建器的情况下将操作放在一起,所以我确信它看起来很糟糕,目标是使用 FPPopover 并让导航栏按钮项目在按下时显示一个弹出窗口

-(void)apopbuttonPressed
{
    //the controller we want to present as popover
    ScribblePopoverViewController * controller = [[ScribblePopoverViewController alloc] initWithStyle:UITableViewStylePlain];
    controller.delegate = self;
    apop = [[FPPopoverController alloc] initWithViewController:controller];

    //apop.arrowDirection = FPPopoverArrowDirectionAny;
    apop.tint = FPPopoverDefaultTint;

    if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
    {
        apop.contentSize = CGSizeMake(300, 500);
    }
    else {
        apop.contentSize = CGSizeMake(200, 300);
    }

    apop.arrowDirection = FPPopoverArrowDirectionAny;

    //sender is the UIButton view
    // idk  [apop presentPopoverFromView:];
}
4

1 回答 1

0

您将选择器设置为“apopbuttonPressed:”<-结尾:说它需要一个参数

您的方法是“apopbuttonPressed”,没有任何参数。

所以试试

action:@selector(apopbuttonPressed)

或将您的方法更改为

apopbuttonPressed:(id) sender

编辑:这是一个工作代码片段:

这是我的代码,它工作正常:

- (void)viewDidLoad {
    [super viewDidLoad];

    UIBarButtonItem * popbutt = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(apopbuttonPressed:)];

    self.navigationItem.rightBarButtonItem = popbutt;
}

- (void) apopbuttonPressed:(id) sender
{
    NSLog(@"pressed");
}
于 2013-02-26T21:09:07.670 回答