views:

53

answers:

2

If I add the button straight everything goes fine. I'd really like to add it inside a view and still be able to click it. Here's the code:

UIView *containerView =
[[[UIView alloc]
initWithFrame:CGRectMake(0, 0, 300, 60)]
autorelease];
UIButton *footerButton = [UIButton buttonWithType:UIButtonTypeCustom];
footerButton.frame = CGRectMake(10, 10, 300, 40);
[footerButton addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];
[containerView addSubview:footerButton];
+1  A: 

This @selector(click) looks a little odd. I would have thought your click function would like something like:

- (void)click:(id)sender;

If that's what you have then you need to add the colon @selector(click:) to make the signatures match.

No one in particular
I just changed the code to make it brief, it's obviously not like that
gurghet
+1  A: 

All works fine! In your TableViewController do:

- (void)viewDidLoad {
    [super viewDidLoad];

    UIView *containerView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 60)] autorelease];
    UIButton *footerButton = [UIButton buttonWithType:UIButtonTypeCustom];
    footerButton.frame = CGRectMake(10, 10, 300, 40);
    [footerButton addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];
    [containerView addSubview:footerButton];

    [footerButton setTitle:@"Touch me!" forState:UIControlStateNormal];
    containerView.backgroundColor = [UIColor colorWithWhite:0.5 alpha:0.5];
    self.tableView.tableFooterView = containerView;
}

- (void)click {
    NSLog(@"I am here!");
}
nepo
Thanks but unfortunately I load it in the footerviewforsection: method
gurghet