Trying to implement a slide out menu in one of my apps. When a user presses an option in the side menu it takes them to another view.
Was working find with the defaults that came in the example of the slide out menu I am using, but when I have my own in it is throwing up an error.
Here is the code:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
DEMONavigationController *navigationController = [self.storyboard instantiateViewControllerWithIdentifier:#"contentController"];
NSLog(#"Row preseed%ld", (long)indexPath.row);
NSLog(#"section preseed%ld", (long)indexPath.section);
if (indexPath.section == 0 && indexPath.row == 0) {
QuickGlanceViewController *homeViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"homeController"];
navigationController.viewControllers = #[homeViewController];
}
self.frostedViewController.contentViewController = navigationController;
[self.frostedViewController hideMenuViewController];
}
And here is the error:
Terminating app due to uncaught exception
'NSInternalInconsistencyException', reason: 'UINavigationControllers
are not allowed in a navigation controller!'
Anyone have any idea what the problem may be?
It looks like QuickGlanceViewController is a subclass of UINavigationController have a look at your nib layout in the storyboard.
You can't have a UINavigationController inside of another UINavigationController.
Related
In my app I am using the following didSelectRowAtIndexPath method to go to a viewController, but I am working within an story Board, and an exception is thrown telling me that the nib file is not found. How should I change the method to open the new viewController without exceptions?:
//link to the next view
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
EmpresasTableViewController *detailViewController = [[EmpresasTableViewController alloc] initWithNibName:#"EmpresasTableViewController" bundle:nil];
detailViewController.title =[[categorias objectAtIndex:indexPath.row]objectForKey:#"idCategoria"];
detailViewController.categoriaDescription = [categorias objectAtIndex:indexPath.row];
[self.navigationController pushViewController:detailViewController animated:YES];
}
you have to make an identifier (detailViewController for example)for you ViewController in your storyboard and then instantiate like this your EmpresasTableViewController
EmpresasTableViewController *detailViewController =[self.storyboard instantiateViewControllerWithIdentifier:#"detailViewController"];
i hope that help you
Firstly, I tried all segue codes but not true result...
(iOS 7) My storyboard starts with Tab Bar and has a Button to Model -> Table View with Navigation Controller. That TableView has JSON datas. If click a cell you pass to another tableViewController with push segue.
My push codes:
KatAltViewController * ilet = [[KatAltViewController alloc] init];
Kategoriler * currentKategoriler = [kategorilerArray objectAtIndex:indexPath.row];
ilet.cid = currentKategoriler.cid;
[self.navigationController pushViewController:ilet animated:YES];
First tableView has not problem but if you click a cell to second table view, console gives that error:
2013-12-23 17:08:59.871 project02[3903:70b] nested push animation can result in corrupted navigation bar
2013-12-23 17:09:00.238 project02[3903:70b] Finishing up a navigation transition in an unexpected state. Navigation Bar subview tree might get corrupted.
So, i click Back button in second tableview: screen is black!
2013-12-23 17:10:34.081 project02[3903:70b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Can't add self as subview'
how I fix that?
If you already have NavigationController in your storyboard and if you use this code
[self.navigationController pushViewController:ilet animated:YES];
you call 2 times to NavigationController.
So can you try this code part?
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
passElement=[array1 objectAtIndex:indexPath.row];
[NSTimer scheduledTimerWithTimeInterval:0.1f target:self selector:#selector(passToOtherTableView) userInfo:nil repeats:NO];
}
-(void)passToOtherTableView{
[self performSegueWithIdentifier:#"passSegue" sender:self];
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([segue.identifier isEqualToString:#"passSegue"]){
SecondTableViewController *controller = (SecondTableViewController *)segue.destinationViewController;
controller.value = passElement;
}
}
I hope this can be help for you.
thanks for all answers.
Yes #TwentyThr23, i called two times NavigationController...
I deleted these codes, because I already push cells on storyboard;
KatAltViewController * ilet = [[KatAltViewController alloc] init];
Kategoriler * currentKategoriler = [kategorilerArray objectAtIndex:indexPath.row];
ilet.cid = currentKategoriler.cid;
[self.navigationController pushViewController:ilet animated:YES];
and I added these lines;
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"altKategoriS"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
KatAltViewController *destViewController = segue.destinationViewController;
Kategoriler * currentKategoriler = [kategorilerArray objectAtIndex:indexPath.row];
destViewController.cid = currentKategoriler.cid;
}
}
I have a default master-detail table view with a menu. The menu works, but for some reason I get the following error when pressing the '+' button to add another cell in my app:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'unable to dequeue a cell with identifier Cell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'
I searched for a solution for days
If I add to viewDidLoad:
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:cellIdentifier];
I don't get the error, but the cells that are added aren't the ones configured in my storyboard, nor do they point to the detail view controller.
I have checked multiple times if the identifier field for the prototype cell has been filled in and is the same as *cellIdentifier.
From what I know it seems of the same nature as the question asked here.
Any help would be appreciated and if you have the time please explain why it's wrong what I did or why certain code should be added.
Requested code (both are default code added by Xcode 5.0.1):
// Code to add the button
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:#selector(insertNewObject:)];
self.navigationItem.rightBarButtonItem = addButton;
// Code called when button is pressed:
- (void)insertNewObject:(id)sender
{
if (!_objects) {
_objects = [[NSMutableArray alloc] init];
}
[_objects insertObject:[NSDate date] atIndex:0];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self.tableView insertRowsAtIndexPaths:#[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
NSDate *object = _objects[indexPath.row];
cell.textLabel.text = [object description];
return cell;
}
Also check out the pictures and project files added in the comment
Replace the following line in [MAAppDelegate application:didFinishLaunching]
UINavigationController *masterViewController = [[UINavigationController alloc] initWithRootViewController:[MAMasterViewController new]];
with
UINavigationController *masterViewController = (UINavigationController *)self.window.rootViewController;
When the app reaches didFinishLaunching, the root view controller has already been configured from the storyboard (if you look at your storyboard, the root view controller is the one with the arrow pointing to it). Note that this process relies on the initWithCoder: initializer.
In didFinishLaunching you're discarding this view controller, replacing it with an instance of TWTSideMenuViewController, which you've configured with new, non-storyboard instances of UINavigationController and MAMasterViewController. If you think about it, there's no way for [MAMasterViewController new] to know that it should be configured from a particular storyboard element. There is actually an API for instantiating view controllers from the storyboard: [storyboard instantiateViewControllerWithIdentifier:]. But you don't need to do that since it's already been done for you.
So the solution is simple. Just configure TWTSideMenuViewController with the existing root view controller self.window.rootViewController.
I have a tabbed view application which uses a tab controller as the root view controller. One of the views I have is a tableview with I want to be able to edit by clicking on an add/edit button that will make all the cells editable as well as allowing to add a cell.
In the table view I have added a navigation bar and have tried to use the following code to create a button on the bar that when pressed will make all the cells editable:
- (void)viewDidLoad {
[super viewDidLoad];
UIBarButtonItem *editButton = [[UIBarButtonItem alloc]
initWithTitle:#"Delete"
style:UIBarButtonItemStyleBordered
target:self
action:#selector(toggleEdit:)];
self.navigationItem.rightBarButtonItem = editButton;
}
-(IBAction)toggleEdit:(id)sender {
[self.mTableView setEditing:!self.mTableView.editing animated:YES];
if (self.mTableView.editing)
[self.navigationItem.rightBarButtonItem setTitle:#"Done"];
else
[self.navigationItem.rightBarButtonItem setTitle:#"Delete"];
}
The code doesn't work, it doesn't produce a button on the navigation bar. I have read that I should use a navigation controller but if I wish to have this one page (in my tabbed view app) use a navigation controller how do I get the tab bar to point to the nav controller as a selection option?
----Update-----
Ok Ive made a nib file that contains the root view controller (a tab bar controller). The tab bar controller contains 2 view controllers and a navigation controller with a view controller in it. I link the View controller in the Navigation controller to a View that contains a tableview. When I run the program and try to click on the tab for the tableview I get the following error:
2012-04-29 17:23:28.116 ash[6778:f803] -[UIViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x68bb8d0
2012-04-29 17:23:28.117 ash[6778:f803] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x68bb8d0'
My view controller that contains the tableview is a UIViewController that implements
In its m file it contains the following methods:
#pragma mark -
#pragma mark Table View Data Source Methods
- (NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section {
return [self.portfolioArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *SimpleTableIdentifier = #"CellTableIdentifier";
static BOOL nibsregistered = NO;
if (!nibsregistered) {
UINib *nib = [UINib nibWithNibName:#"ASHInstrumentCell" bundle:nil];
[tableView registerNib:nib forCellReuseIdentifier:SimpleTableIdentifier];
nibsregistered = YES;
}
ASHInstrumentCell *cell = [tableView dequeueReusableCellWithIdentifier:
SimpleTableIdentifier];
NSUInteger row = [indexPath row];
cell.type.text = [portfolioArray objectAtIndex:row];
return cell;
}
#pragma mark -
#pragma mark Table Delegate Methods
- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSUInteger row = [indexPath row];
NSString *rowValue = [portfolioArray objectAtIndex:row];
NSString *message = [[NSString alloc] initWithFormat:
#"You selected %#", rowValue];
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:#"Row Selected!"
message:message
delegate:nil
cancelButtonTitle:#"Yes I Did"
otherButtonTitles:nil];
[alert show];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
- (void)tableView:(UITableView *)tableView commitEditingStyle: (UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
NSUInteger row = [indexPath row]
[self.portfolioArray removeObjectAtIndex:row];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic] ;
}
What am I doing wrong?
Two points: First of all, a UINavigationController is a subclass of UIViewController, so you could create an instance of UINavigationController whose rootViewController is your tableViewController, and have the TabBarController manage the nav controller as one of its tabs.
Also note that the UIViewController class already has a editButtonItem property that you should use instead of creating your own button:
self.navigationItem.rightBarButtonItem = self.editButtonItem;
Ok I think I figured out what I was doing wrong. I had created a nib file for my tab view controller and to this I added to view controllers and a Navigation controller (which itself contained a tableview controller).
One of the things I wasn't doing was allocating the correct class type to the view controllers in my tabs. If I have created a custom view controller class firstviewcontroller which had IBOutlets and I didn't specify the view controller in my tab controller nib to be of class firstviewcontroller I would get that weird key value error.
The second problem I had was that the tab view controller wouldn't autorotate even though all the view I wanted to show allowed for autorotation using the following code:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return YES;
}
The reason for this again was that I hadn't specified the class of each of the view controllers (in my tabbedviewcontroller nib file) to be of my custom made classes that I wished them to show.
Once I specified their class type everything fell into place.
I have started working with story board ,a new feature in iOS 5,so I started with a tabbed application,then I added a table view controller and filled the cells with some dummy data,now,the table has 4 cells,now on click of each cell,I want to open a newViewController,which will be diffrent for each cell,
So previously,I used to code this way
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
if(indexPath.row == 0)
{
FirstViewController *settingsView =[[FirstViewController alloc]initWithNibName:#"FirstViewController" bundle:nil];
[self.navigationController pushViewController:settingsView animated:YES];
}
if(indexPath.row == 1)
{
SecondViewController *settingsView =[[SecondViewController alloc]initWithNibName:#"SecondViewController" bundle:nil];
[self.navigationController pushViewController:settingsView animated:YES];
}
if(indexPath.row == 2)
{
ThirdViewController *settingsView =[[ThirdViewController alloc]initWithNibName:#"ThirdViewController" bundle:nil];
[self.navigationController pushViewController:settingsView animated:YES];
}
}
But know,how shall I do it..please help me out
Thanks & Regards
Ranjit
Maybe this tutorial would help you?
http://kurrytran.blogspot.com/2011/10/ios-5-storyboard-uitableview-tutorial.html
As I see this (performSegueWithIdentifier:sender:) should be the method to perform a new viewcontroller from the storyboard
https://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instm/UIViewController/performSegueWithIdentifier:sender: