I'm new to iOS development and I'm having a big headache not understanding something that may be pretty easy. Basically I'm using a UITableViewController to go to another UITableViewController, but then I need to go from that second UITableViewController to a UIViewController. I want this UIViewController to have a .xib file for me to make a quick UI but I can't seem to find the way to push from the Second UITableViewController to this UIViewController. I managed to programatically show a label, but not a UI from a .xib.
This is the code that works with the programmatic label:
- (void)tableView:(UITableView *)tableView
accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
{
self.detailController.title = @"Disclosure Button Pressed";
NSString *selectedMovie = self.movies[indexPath.row];
NSString *detailMessage = [[NSString alloc]
initWithFormat:@"This is details for %@.",
selectedMovie];
self.detailController.message = detailMessage;
self.detailController.title = selectedMovie;
[self.navigationController pushViewController:self.detailController
animated:YES];
}
And this is the .m of the UIViewController that works to show a UILabel programatically.
@implementation BIDDisclosureDetailViewController
- (UILabel *)label;
{
return (id)self.view;
}
- (void)loadView;
{
UILabel *label = [[UILabel alloc] init];
label.numberOfLines = 0;
label.textAlignment = NSTextAlignmentCenter;
self.view = label;
}
- (void)viewWillAppear:(BOOL)animated;
{
[super viewWillAppear:animated];
self.label.text = self.message;
}
@end
Basically I don't want to create any UIObject Programatically, I need a .xib to create the UI.
Thanks
(iOS 6, not using storyboards)
Loading up a UIViewController
from a xib is easy. When your tableview delegate sends the didSelectRowAtIndexPath:
message you can load up a xib and present the view controller as follows:
BIDDisclosureDetailViewController *controller = [[BIDDisclosureDetailViewController alloc] initWithNibName:@"BIDDisclosureDetailView" bundle:nil];
[self.navigationController pushViewController:controller animated:YES];
Some things to note:
initWithNibName:bundle:
loadView
code you have in there as well, it will mess things up when trying to use the xib.Side note! you should not have semi-colons at the end of method signatures like this one:
- (void)viewWillAppear:(BOOL)animated;
It is considered bad form.
Hope this helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With