RESideMenu show selected item - ios

I'm using this for the menu in my app: https://github.com/romaonthego/RESideMenu and I want to be able to show the selected item in order to make it more clear which view the user is currently on. Would I be able to do this in the cellForRowAtIndexPath method?

RESideMenu controller is a container controller like UITabBarController or UISplitViewController. That means that you specify content view controllers (in case of RESideMenu: content (front), right menu and left menu view controllers) and let container controller handle their display in a way that controller wants. That means that you can track which view controller you supplied to RESideMenu and highlight your cells depending on that information.
For example, you can associate a view controller instance with each menu cell and then:
if (cellBackingObject.viewController == reSideMenu.contentViewController)
{
// highlight cell
}
else
{
// don't highlight cell
}
Note, that you should reasonably manage view controller's life, because storing all of them in memory is not always good.

Related

How to find the identifier of the navigationController from a ViewController?

I have a 2 navigation controllers in a Tab Bar Controller which point to same View. This gives me 2 different instances of that view in 2 different tabs. Now I want the view to behave differently based on its parent Navigation Controller.
if id == "parent1"{
//do something
} else {
//do something else
}
So how can I get the identifier of the navigationController in ViewController code?
You can use the restorationIdentifier which you can set in the storyboard; It's right underneath the storyboard identifier field in the identity inspector.
Get the current navigation controller from the view controller's property
let id = self.navigationController.restorationIdentifier
Note that by setting this property, you are telling the system the view controller should be saved for restoration, which might have unexpected consequences. See documentation.
Alternatively, you might want to consider using subclasses or some kind of property on your view controller class (e.g. maybe using IBInspectable etc).

Assigning two views to a single Container View using swift in iOS 8

I am trying to assign two view controllers to a Container View using the Interface Builder. I tried to do so, but whenever I try to "embed" the second view controller to my Container View, instead of adding another VC to it, it just replaces the one that was embedded already.
Ultimately, my main goal is to have a screen that has the following elements (in order, from top to bottom):
-A navigation bar
-A view of height 50 that contains a segmented controller (which will switch between tableVCs)
-A main view, which will contain my Container view
-A tabbed bar
My current setup is almost as described above. Here is a picture:
The view controller I am interested in the most is in the one with the highlighted container(HomeViewController). The approach I am currently using is hacky, because I currently have 2 container views, one on top of another, and they embed the 2 table view controllers depicted to the right (one per container).
I do not like this approach very much because both containers get instantiated whenever the main VC (Home View Controller) is instantiated, therefore making 2 network calls by default to load their content, possibly slowing down the device and maybe using more memory than needed.
Ideally, I would load the content of one table view controller that is mapped to one of the segmented controls. Then, I would have a mechanism that somehow instantiates the second table view controller whenever I go to the second button in the segmented control (and possibly deallocating/getting rid of the other VCs), and so on with the third. Or somehow be able to display/alternate between 2 or more view controllers in an area (view) inside my HomeViewController.
Currently I have this simple code that switches (hides and shows) between container views in my HomeViewController:
#IBAction func segmentChanged(sender: AnyObject) {
switch segmentedControl.selectedSegmentIndex{
case 0:
println("index1 selected")
containerView1.hidden = false
containerView2.hidden = true
break
case 1:
println("index2 selected")
containerView1.hidden = true
containerView2.hidden = false
break
default:
containerView1.hidden = false
containerView2.hidden = true
break
}
}
As I said, this only switches between the views that are loaded already in my view controller, with the data in them already.
I just wanted to see if what I am trying to code is doable, or if I am actually tackling the problem the right way, although I doubt I am doing so.
Thank you for reading my post and for your advice in advance.
Cheers!
Add embed segue to NavigationController, add ViewController as rootViewController to NavigationController, from rootViewController add as many segue as you wish. To load controller you need just override segue class to push without navigation.
class NoAnimationSegue: UIStoryboardSegue {
override func perform() {
self.sourceViewController.navigationController?.pushViewController(self.destinationViewController, animated: false)
}
}

Next Page on click by page based application

In my page based application i want to perform the operation next page on click of button?Is it possible to to go next page using button in page based application?Pls help me to solve this issue
Edit: My application like story book im showing set of images in pages while turning next page, i want to show the nxt page by click
In your app the class conforms to the UIPageViewControllerDataSource protocol, make one object of this class in root view controller suppose ModelController then the object is _modelController.
Then in root view controller just put two UIButton connect them with appropriate IBAction methods suppose for previous button previousClick: and for next button nextClick:.
Now the code for each method is as follow:
-(IBAction)previousClick:(id)sender { [_modelController pageViewController:self.pageViewController viewControllerBeforeViewController:_dataViewController]; }
-(IBAction)nextClick:(id)sender { [_modelController pageViewController:self.pageViewController viewControllerAfterViewController:_dataViewController]; }
Here I suppose that the pageViewController is the one object of type UIPageViewController and is one of the declared and synthesized variable of root view controller, and also same for the _dataViewController which is one UIViewController contains one UIImageView to present the images on the root view.
EDIT
This also can be done with the using the DataViewController for that all the logic have to move to that view controller and all so the references must be needed for the UIPageViewController and ModelController.

How to add iPad subview controller to act like a Tab Bar

I have an app that I just got setup with a split view controller to display blogs on the ipad version of the app. The current setup is master controller is a table view to show the different articles off the blog, and the detail controller is a view controller with a webview inside used to show the content of the article. The issue is that I have a few other features in the app, and on the iPhone version, I use a tab bar controller to navigate. What would be some options to add buttons to the detail controller that would allow me to navigate to the other sections of the app? I know I can't get a Tab Bar Controller within the Split View Controller so I just need some guidance.
I know that the Engadget app is setup so that when you open in portrait mode, it shows the table view of apps, along with a controller at bottom to go to different things like photos, and when in landscape the table view is on the left and the text of the articles is on the right. I just want it set up so there is no blank page if you open in portrait mode, and have a feature to view other pages, besides just adding buttons to the navigation bar.
you CAN add a tabBarController to your SplitViewController's detail view. Simply create a UIViewController that responds to <UITabBarControllerDelegate> and in the xib file for that controller add a UITabBarController object and link it to your UIViewController. In your viewDidLoad add the Tab bar controller to the view:
-(void)viewDidLoad {
...
[self addChildViewController:myTabBarController];
//add the tabBarController view
[self.view addSubview:myTabBarController.view];
}
This UIViewController will be assigned to your detail view. this works and I've tried it before. However, whether apple would allow it? i don't know!
EDIT:
first of you should never call viewDidLoad yourself.
Also, i don't think you need rootipad and detailipad as long as the controllers are linked to the SplitViewController in the xib file.
in your RootViewiPad (master) add the following inside its viewDidLoad :
-(void)viewDidLoad {
...
if (self.interfaceOrientation == UIInterfaceOrientationPortrait || self.interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
//select the first row to load
[self.tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:NO scrollPosition:UITableViewScrollPositionNone];
//NOTE, I'm assuming that selecting the cell will load the detail view.
//if that is not the case, you need to do what ever you need to load the
//detail view.
}
}
if you want this behavior to happen every time (not only on first load) then add the code to the -(void)viewWillAppear method instead.

iOS: Setting text in nib subview from view in UITabBar/UINavigationController application

I'm having a problem getting a UISearchDisplay's text value to be set programatically on load of the view by another view and my question is have I overcomplicated my problem and missed something or am I on the right track of thinking.
Here's the situation: I have a UITabBarController as my root view, there are 2 tabs, both have a UINavigationController setup so I can push views as needed.
Tab 1 has a UITableViewController which is populated with a list of categories.
Tab 2 has a MapView in it's main view but I have done a custom UINavigationItem view to put various buttons and a UISearchDisplay on the rightBarButtonitem area.
The mapview layout and custom navigation item are stored in the same nib as two separate view objects. In Tab 2's viewDidLoad(), I initialise the rightBarButtonItem programatically with:
UIBarButtonItem *btnItem = [[UIBarButtonItem alloc] initWithCustomView:buttonBar];
self.navigationItem.rightBarButtonItem = btnItem;
[btnItem release];
Everything fires up, buttonBar is wired up to an IBOutlet as searchWhat and I can talk to this object from within the mapview's controller class.
If the user is in Tab 1 and taps a cell, I want it to switch to Tab 2 and populate the searchWhat.text and then execute the search code as if someone had typed in the search themselves.
What i'm having trouble with is the order of load and populate on a view.
I can access the 2nd tab from the 1st without any problem and get it to appear with something like:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(#"Quick Category cell tapped at row %d", indexPath.row);
self.tabBarController.selectedIndex = 1; // change to the search view controller
//[self.tabBarController.selectedViewController viewDidAppear:YES];
UINavigationController *nav = (UINavigationController *)self.tabBarController.selectedViewController;
SearchViewController *srch = [nav.viewControllers objectAtIndex:0];
//NSLog(#"%#", [srch description]);
[srch queueSearchByType:kSearchTypeQuickCategories withData:[catList objectAtIndex:indexPath.row]];
[srch viewDidAppear:YES];
}
Don't worry about catList and SearchViewController, they exist and this bit works to switch tabs.
Here's the problem though, if the user starts the application and selects an item in tab 1, tab 2 appears but the values of the search display text don't get set - because viewDidLoad and viewDidAppear are called in another thread so the execution of queueSearchByType:withData: gets called while the view is still loading and setting up.
If the user selects tab 2 (therefore initialising the subview) and then selects tab 1 and an item, it can populate the search display text.
I can't just change the order of the tabs so that tab2 is first and therefore loads it's subviews to the navigation bar as the project specification is category search first.
Have I missed something very simple? What I need to do is wait for the second tab to fully appear before calling queueSearchByType:withData: - is there a way to do this?
At the moment, i've implemented a queue the search, check for a queue search approach, this seems to be a bit long winded.
Ok, I don't like answering my own question but it appears my fears were right, basically if you want a UINavigationItem that is a custom view (ie, to put a search bar and various other buttons up on the nav controller) and be able to switch to and populate them from another tab on a tab bar controller, then you need to put the subview in it's own class which is a subclass of UIViewController and then make delegation your friend (which it already is), i've provided an example in case anybody needs to repeat it which i've put on my blog HERE.
http://www.jamesrbrindle.com/developer/ios-developer/howto-add-a-custom-uinavigationitem-to-a-uinavigationcontroller-with-delegation.htm
If anyone disagrees and thinks this can be simpler, please let me know or rate this post

Resources