UIViewController Problem with IB
This is what I do
- Setup a view with UIViewController Subclass
- Go to IB, and pull a view into the iphone
- Pull a navigation bar over the UIView
- Pull a tableview on the space below.
Everything appears well when I am running the interface builder.
But these things do not work.
If I add a button on top of the Navigation Bar, the button appears but IBAction is not called. The button seems to be at a level beneath the Navigation Bar (somewhere else)
If I add a footer view for the tableView, it does not appear. I believe the UIView is again masking it or something...
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { UIView *viewForFooter = [[UIView alloc] init ]; UIButton *footerButton =开发者_如何学Go [[UIButton alloc] initWithFrame:CGRectMake(200, 40, 100, 40)]; footerButton.titleLabel.text = @"Forgot Login"; //self.forgotLogin = footerButton; [viewForFooter addSubview:footerButton]; return viewForFooter; }
WHY ?
1) No reaction to click: Try to add the action in code. If it works, something was wrong with connecting up the IBAction.
[self.barButton setTarget:self];
[self.barButton setAction:@selector(IBActionHandler:)];
As a backup, you can also try to add the button in code:
UIBarButtonItem *barButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemDone
target:self
selector:@selector(IBActionHandler:)];
self.navigationItem.rightBarButtonItem = barButton;
[barButton release];
2) Invisible button - I think your button is a custom UIButton, so it is transparent. The title is not visible because you have to set it like this:
[footerButton setTitle:@"Forgot Login" forState:UIControlStateNormal];
If you want a regular rounded angle button you have to set the frame after creating it.
UIButton *footerButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
// Careful, this button is autoreleased.
[footerButton setFrame:CGRectMake(200, 40, 100, 40)];
BTW, something might also be wrong with your CGRects. The footerView should perhaps also be properly initialized with a frame, and you might have to implement
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
as well.
PS: To go with a standard UITableViewController might actually be a good idea. Happy coding!
精彩评论