UINavigationController - JTRevealSidebar - objective-c

I have a problem which is in JTRevealSiderbar's Sidebarviewcontroller , where sidebar button pressed delegate i am calling a code like :
OpeningViewController *controller = [[OpeningViewController alloc] init];
controller.view.backgroundColor = [UIColor clearColor];
//controller.title = (NSString *)object;
controller.leftSidebarViewController = sidebarViewController;
controller.leftSelectedIndexPath = indexPath;
sidebarViewController.sidebarDelegate = controller;
NSArray *viewControllerArray = [[NSArray alloc] initWithObjects:controller, nil];
[self.navigationController setViewControllers:viewControllerArray];
i have checked that from the baseviewcontroller , siderbarviewcontroller and my openingviewcontroller , uinavigationcontroller's memory address is the same.
besides , when i call the code above , OpeningViewController's viewdid load and appear also called without problem.
but here's my problem , view is not shown !? i could not figure out why is this problem.
i have checked that self.navigationController's viewControllers property is null? maybe this is the problem but i also could not figure out why navigationcontroller's viewcontrollers are empty?
someone help me please , any thought will be appreciated! :)

since i am using storyboard and segues , i have created a viewid for my storyboard for each of the viewcontrollers and create each viewcontroller with their storyboard ids . when i implemented this i just needed to give a background image to my each viewcontroller (still i do not know why this happened) . but this solved my problem totally.
if you need any help about this , you can comment on this then i'll pass some codes.

Related

ViewController issue in Xcode?

I am fairly new to Xcode, but I have run into a bit of a problem. I have a tabbed view controller, and one subtab has a UITableView. On cell click, I need TableData (a ViewController) to open up. For some reason, I just get a black screen. I then changed my code to this:
TableData *newView = [self.storyboard instantiateViewControllerWithIdentifier:#"TableData"];
[self presentViewController:newView animated:YES completion:nil];
but I get an error SIGABRT in Xcode. How do I fix this?
This works, but gives me a black screen:
TableData *view = [TableData alloc];
view.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController: view animated:YES];
Just create an identifier for the segue inside the storyboard and then use:
[self performSegueWithIdentifier:#"yourTableViewStoryboardSegueIdentifier" sender:self];
UPDATE:
Problem was most likely due to user grabbing an invalid row from his tableView. In order to just grab the row number all you need to do is:
int rowNumberSelected = indexPath.row;
As for his second code snippet, the reason its only showing a black screen is because he is not actually linking it to his viewController in the storyboard. He is simply just allocating the code. If he added subviews through the code, then they would show up but nothing from the storyboard.
Since the user is using Storyboard, its always better to just use segues and dismissals however.

Can we put navigationcontroller in MasterView in iPad Application?

I have worked mostly on iPhone apps. Now I need to build an iPad app. In that I need to put NavigationController in the MasterView of the Master Detail View of the iPad as we do in the UITableView in the iPhone. I mean when user selects a particular row it should navigate to another tableview with newly filled data. and user can go to the previous by pressing back button. Also On each selection I need to make change of image in the detail view.
I dont have any idea to achieve this.
Please provide any suggestions or any sample code for it.
Thanks in advance.
try this in your appDelegate didFinishLaunchingWithOptions method
MasterViewController *masterViewController = [[[MasterViewController alloc] initWithNibName:#"MasterViewController_iPad" bundle:nil] autorelease];
UINavigationController *masterNavigationController = [[[UINavigationController alloc] initWithRootViewController:masterViewController] autorelease];
DetailViewController *detailViewController = [[[DetailViewController alloc] initWithNibName:#"DetailViewController_iPad" bundle:nil] autorelease];
UINavigationController *detailNavigationController = [[[UINavigationController alloc] initWithRootViewController:detailViewController] autorelease];
self.splitViewController = [[[UISplitViewController alloc] init] autorelease];
self.splitViewController.delegate = detailViewController;
self.splitViewController.viewControllers = [NSArray arrayWithObjects:masterNavigationControlle, detailNavigationController, nil];
self.window.rootViewController = self.splitViewController;
[self.window makeKeyAndVisible];
This is certainly possible. There are no limitations on what you can display in the master and detail views of a split view controller.
Think of the split view as merely a view that displays two of your view controllers. They can contain anything.
If I understood what you're trying to achieve correctly then what you want to do is create a View Controller with a UITableView which will display the data in the left column. This View Controller should also have a UINavigationController which will push another view controller when you select something in the table.
So far, so good. Nothing has changed in the detail view since it in reality isn't aware of or connected to the master view in any way. When the user has moved enough steps down in the master view, and you want to change the detail view - then you can set the viewControllers-property of the navigation controller to update the detail view with whichever view controller you want to display.
Yes you can. Apple has provided a sample code called MultipleDetailViews
It shows how communication is done between master and detail using delegation.
See these Tutorials :-
http://www.icodeblog.com/2010/04/05/ipad-programming-tutorial-hello-world/
http://www.raywenderlich.com/1040/ipad-for-iphone-developers-101-uisplitview-tutorial
These will help you.

How to get data into textfields for editing?

I have this code (XCode 4, using Storyboards with ARC) which takes data from an array (rArray) and places it in the textfields from which it originally came from (I want to edit the data). The array (rArray) has valid data in it, but nothing is in the textfields. What am I doing wrong?
SingletonListOfReadings *rShareInstance = [SingletonListOfReadings sharedInstance];
rArray *ra = [rShareInstance.listOfReadings objectAtIndex: indexPath.row]; // get an rArray object out of listOfReadings
// place data back into textfields
EnterDataViewController *edvc = [[EnterDataViewController alloc] init];
edvc.txtSTA1.text = ra.rSTA;
edvc.txtBS.text = ra.rBS;
edvc.txtFS.text = ra.rFS;
edvc.txtDesc.text = ra.rDesc;
[self.navigationController pushViewController:edvc animated:YES];
the UI text elements in VC are not yet set when you try to populate it (it will be set only after [self.navigationController pushViewController:edvc animated:YES]; (and only when it gets viewDidLoad).
easy way to go is to change txtSTA1, txtBS, txtFS etc to strings (make sure they are in edvc .h file), pupulate them as u do now
so, txtSTA1STR is a string in the .H file of edvc
and txtSTA is a UI text element in the xib (or programmatically) in edvc
EnterDataViewController *edvc = [[EnterDataViewController alloc] init];
edvc.txtSTA1STR = ra.rSTA;
edvc.txtBSSTR= ra.rBS;
edvc.txtFSSTR= ra.rFS;
edvc.txtDescSTR= ra.rDesc;
[self.navigationController pushViewController:edvc animated:YES];
and inside edvc
- (void)viewDidLoad
{
txtSTA1.text = txtSTA1STR;
//... etc
}
I fixed it... I took the original code and moved it to the View controller (edvc) which handles the objects. Then I called it from the view controller where I needed the data.
Works fine... I think the problem was in the addressing of the receiving textfields.
Thank you for your help... I appreciate it.

UIPopOverController inside UISplitViewController

I have to show one popOver inside the left side of one splitController, I initialize the popOver whit an navigationController. But when i show the popOver my app crash.
Impostazioni *settings = [[Impostazioni alloc] initWithStyle:UITableViewStyleGrouped];
settings.title = NSLocalizedString(#"SETTINGS", nil);
settings.contentSizeForViewInPopover = kContentSizeOfPopOver;
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:settings];
nav.navigationBar.tintColor = kTintColorNavigationBar;
nav.contentSizeForViewInPopover = kContentSizeOfPopOver;
UIPopoverController *popOver = [[UIPopoverController alloc] initWithContentViewController:nav];
[popOver presentPopoverFromBarButtonItem:self.navigationItem.rightBarButtonItem permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
This is my code. Any ideas?
EDIT: Crash even if I set only a viewController instead of SplitController :/ And with a empty ViewController :/
(Possibly duplicate of Error using UIPopoverController.)
In short, you need to retain the UIPopoverController somehow. Either by defining a property for it or by managing the ref count manually. With ARC, the latter is not an option, so you need to store the reference.
I believe you need an instance variable to hold the popoverController. Otherwise after the method that contains the code that you showed finishes nothing will have retained your popover. Unlike when you add a subview to a view which the view would then retain the subview. The same thing does not take place for popovers.

UISpliviewcontroller in recursive calls fail after a memory warning

Any help is appreciated ! It's several days I'm fighting w/o results.
The scenario:
I and iPad application have a SplitViewController that shows 2 controllersViews (Root on the left e Detail on the right)
The Root allows a recursive navigation (tree that could be several drilldown levels) and I'm calling every time the same controller class (UITableView) pushing always in the controller stack). When the user taps a cell (left side), the detail view (right side) shows the information.
Keep in mind that the detail view controller is not always the same class: it means that I'm allocating (and releasing) programmatically several detailView controllers according the kind of information I have to display.
Here the fragment:
UIViewController <ItemGenericViewController> *newDetailViewController = [[NSClassFromString(cntrClass) alloc] initWithNibName:cntrXib bundle:nil];
//the detailViewController has been defined in the head section as ItemGenericViewController
//each detailViewController is a subclass of ItemGenericViewController
detailViewController = newDetailViewController;
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:detailViewController];
// Update the split view controller's view controllers array.
NSArray *viewControllers = [[NSArray alloc] initWithObjects:self.navigationController, nav, nil];
self.splitViewController.viewControllers = viewControllers;
[nav release];
[viewControllers release];
[detailViewController release];
Everything is working fine until a memory warning arises.
From that moment if I try to display a new detailViewcontroller the "connection" in the SplitViewController, between the RootController and the detailController, seems vanished. The result is: nothing appear on the right part of the splitController.
In the mean time if I navigate to parent level in the root controller the situation still failing.
For your information each time I push in the stack a new RootController instance (left column) I'm releasing the same controller (to save memory as usual) and I suspect, after receiving the memory warning, iOS is trying to free itself memory and my "history" disappear and the related connection, throught the split controller, too.
Is a nightmare ;-)
Do you have any suggestion ?
Thanks
Dario
I had a similar problem to you (maybe even worse - 16 combinations of possible view switches)... But I believe i have solved it right now.
So, i believe you have used Apple's example for view switching (I have, with modifications), and if you have so, problem is that "root" splitViewController (from MainWindow.xib) get's "niled" as default behavior when memory warning. And even if you add new array of view controllers to it, it will not cause any change (and even worse, it will not show any sign of warning). And solution is to check is it nil, and if is, to reinitialize it.
here is the code, using example from above:
UIViewController <ItemGenericViewController> *newDetailViewController = [[NSClassFromString(cntrClass) alloc] initWithNibName:cntrXib bundle:nil];
//the detailViewController has been defined in the head section as ItemGenericViewController
//each detailViewController is a subclass of ItemGenericViewController
detailViewController = newDetailViewController;
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:detailViewController];
// Update the split view controller's view controllers array.
NSArray *viewControllers = [[NSArray alloc] initWithObjects:self.navigationController, nav, nil];
/**** Milos Edit ****/
if (self.splitViewController == nil) {
// I'm keeping reference in app delegate, but any way to reinitialize splitViewController is OK
self.splitViewController = delegate.splitViewController;
}
/**** end of edit ****/
self.splitViewController.viewControllers = viewControllers;
[nav release];
[viewControllers release];
[detailViewController release];
Hope it will be helpful.
Cheers
Milos