I have added a UIBUtton in a UITableView header and it doesn’t seem to be working. It’s clickable, but when attaching a IBAction to it, it fails and does nothing.
I have read online and saw to put it in your File’s Owner, but I can’t do that. When I put the action in, it only shows up in my First Responder.
I have also tried to put it in a different file, but when doing do it won’t let me drag it to the other file.
FILES:
RootViewController.h
RootViewController.m
TableViewAppDelegate.h
TableViewAppDelegate.m
DetailViewController.h
DetailViewController.m
RootViewController.h
@interface RootViewController : UITableViewController {
NSMutableArray *listOfItems;
Sqlite *database;
NSTimer *myTimer;
UITextView *myTextField;
}
- (IBAction)addAlbum;
RootViewController.m
#import "RootViewController.h"
#import "TableViewAppDelegate.h"
#import "DetailViewController.h"
@implementation RootViewController
// If a user adds a photo album
- (IBAction)addAlbum {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Add Gallery" message:@"this gets covered" delegate:self cancelButtonTitle:@"Dismiss" otherButtonTitles:@"Ok", nil];
myTextField = [[UITextField alloc] initWithFrame:CGRectMake(12, 45, 260, 25)];
CGAffineTransform myTransform = CGAffineTransformMakeTranslation(0, -80);
[alert setTransform:myTransform];
[myTextField setBackgroundColor:[UIColor whiteColor]];
[alert addSubview:myTextField];
[alert show];
[alert release];
[alert setTag:1];
}
Any help is appreciated!
Thanks.
If you’re loading the table header view from .xib, make “File’s Owner” of the .xib your ViewController subclass presenting the UITableView, and connect the desired event in the button to the desired IBAction in File’s Owner. If you’re creating the button programmatically in a tableView:viewForHeaderInSection: method, you must wire up the action yourself on the button using this method on the button object:
EDIT: you should post your tableView:viewForHeaderInSection: code so we can give more specific advice.