I am trying to place a "Dismiss" or "Done" button in the top right corner in a navigation control for a ModalView that closes the view. Using a normal UIView, I am able to do this. However, when I try to use a UITableView for my ModalView, I am no longer able to set the BarButton's target to a parent controller.
The "dismissModalController" method is in a separate controller than the TableView's, but the button wants to default to the TableViewController rather than using a target Controller where "dimissModalController" is.
How can I replicate the functionality of the button in UIView with that of the UITableView?
UITableView Initiation (Not Working):
-initWithStyle:(UITableViewStyle) style {
ToolbarController *myParent;
if(self=[super initWithStyle:style]) {
self.title=@"Widgets List";
UIBarButtonItem *rightButton =
[[UIBarButtonItem alloc] initWithTitle:@"Dismiss"
style:UIBarButtonItemStyleDone
target:myParent
action:@selector(dismissModalController)
];
self.navigationItem.rightBarButtonItem=rightButton;
[rightButton release];
}
return self;}
UIView Initiation (Works):
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
parent:(ToolbarController*) myParent{
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
UIBarButtonItem *rightButton =
[[UIBarButtonItem alloc] initWithTitle:@"Dismiss"
style:UIBarButtonItemStyleDone
target:myParent
action:@selector(dismissModalController)
];
self.navigationItem.rightBarButtonItem=rightButton;
[rightButton release];
}
return self;
}