0
votes

I attempted to add the barbuttonitem into the xcode proj and finally got it to show up using the view controller and putting the code in the view did load section but I cannot connect the action... I have always used interface builder and IBOutlets but that is not an option as this navigation controller had to be programmatically put in to have the tab bar controller work

- (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.
}

This is my first attempt at putting actions together without using IBOutlet and interface builder so I'm sure it looks pretty bad the goal is to use FPPopover and have the nav bar button item display a popover when pressed

-(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:];
}
1
i tried this and still no response from the button when pushed in the simulatorbryan
this is my code and it works fine: - (void)viewDidLoad { [super viewDidLoad]; NSLog(@"viewdidload"); // Do any additional setup after loading the view, typically from a nib. UIBarButtonItem * popbutt = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(apopbuttonPressed:)]; self.navigationItem.rightBarButtonItem = popbutt; } - (void) apopbuttonPressed:(id) sender { NSLog(@"pressed"); }Thorsten
please see my edited answer..Thorsten
thank you so much i just got off work and will give it a shot im sure that will work. thanks againbryan
ok i put it in and it is logging pressed thats great thanks but now i must ask how do i get it to display the popover when it acknowledges the button is pressedbryan

1 Answers

0
votes

you set the selector to "apopbuttonPressed:" <- the ending : says it expects a parameter

your method instead is "apopbuttonPressed" without any parameter.

So try

action:@selector(apopbuttonPressed)

or change your method to

apopbuttonPressed:(id) sender

EDIT: Here is a working code snippet:

this is my code and it works fine:

- (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");
}