Load every view controllers in tab view - ios

I'm using carbonKit to create a tab view, which contains a dynamic number of tabs. The problem is, each view controller (table views controllers) is loading its content only when I'm going to the tab. I'd like to know if I could load every tabs' content (init and load every view controllers) to navigate flowlessly between each tab.
Here is the code where I init a view controller for a specific tab at index:
- (UIViewController *)tabSwipeNavigation:(CarbonTabSwipeNavigation *)tabSwipe viewControllerAtIndex:(NSUInteger)index {
CommentsTableViewController *tab = [self.storyboard instantiateViewControllerWithIdentifier:#"TabController"];
[tab setPeople:self.peoplepassed];
[tab setQuestion:self.questionpassed];
switch (index) {
case 0:
[tab setTab:#1];
break;
case 1:
[tab setTab:#2];
break;
case 2:
[tab setTab:#3];
break;
case 3:
[tab setTab:#4];
break;
default:
[tab setTab:#1];
break;
}
return tab;
}

Solved by the creator of carbonkit here, should have thought of it earlier, thanks, closed !
EDIT: will mark my own answer as resolved as I have to wait for 2 days

Related

NSInvalidArgument Exception when click next Button in Walkthrough Screens

I am making IntroScreens for iOS app, Every thing is perfect but when I click next button it shows NSInvalidArgumentException error
pageContentViewController
- (IBAction)nextButtonTapped:(id)sender {
switch (self.pageIndex) {
case 0:
case 1:
pageViewController = ((PageViewController *)self.parentViewController);
[pageViewController forward:self.pageIndex];
break;
case 2:
[self performSegueWithIdentifier:#"LoginScreen" sender:nil];
break;
default:
break;
}
}
PageViewController
-(void)forward:(NSUInteger)index{
[self.pageViewController setViewControllers:#[[self viewControllerAtIndexArabic:index +1]] direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:nil];
}
reason: '-[UIPageViewController forward:]: unrecognized selector sent to instance 0x7fb2cf009600
The issue it with the following code block
pageViewController = ((PageViewController *)self.parentViewController);
I guess you have set your pageviewcontroller in storyboard which is an instance of UIPageViewController but in the code you are trying to access PageViewController ( which I guess is a third party controller ).
So you must change the class of your UIPageViewController in storyboard to PageViewController.

How to change a Button action with Segmented Control

I have a button which has an action that gives a push to another view. My goal is to make this button to open different views according to the selected segment. For example: I have a button called "Request" and have a control segment with two segments, called "Pizza Salt" and "Sweet Pizza." When selected, for example, "Pizza Salt" in the segment and then immediately click the "Request" button, I want to open a view to the menu of "Salt Pizza.", And selected "Sweet Pizza" I want the button to open another view with the menu of the "Sweet Pizza."
Note: I already have the two controllers ready with views.
What code do I use?
My code:
- (IBAction)changeButtonCode:(id)sender {
if (_firstSegmentSixthView.selectedSegmentIndex == 0);
}
- (IBAction)pushToNextView:(id)sender {
}
Use this method to perform actions on different buttons of UIsegmentControl:
- (IBAction) segmentControlBtnAction:(id)sender
{
UISegmentedControl* segmentControl = (UISegmentedControl *)sender;
int index = [segmentControl selectedSegmentIndex];
switch(index)
{
case 0: // Perform action on first button of segment controller
break;
case 1: // Perform action on second button of segment controller
break;
case 2: // Perform action on second button of segment controller
break;
default
break;
}
}
Connect this method with UISegmentControl from xib, using the attribute "value changed".
Upon pressing the request button:
if (_firstSegmentSixthView.selectedSegmentIndex == 0) //salty
{
ViewController1 *vc1 = [[ViewController1 alloc] init];
[self.navigationController pushViewController:vc animated:YES];
}
else if (_firstSegmentSixthView.selectedSegmentIndex == 1) //sweet
{
ViewController2 *vc2 = [[ViewController2 alloc] init];
[self.navigationController pushViewController:vc2 animated:YES];
}

xCode Master-Detail change detail viewcontroller from master viewcontroller

I have just created a new "Master-Detail application" project I Xcode 5.
Then on my Master View Controller, I have change the table view to static, and added up a few items: Home, View 1, View 2.
I have removed the default databinding, so when i run it now it appears as intended.
As default my "Home" view is my Detail View Controller.
Now I would like: When i press "View 1" it changes my Detail View Controller to a new view I have created on my storyboard.
But how do I do that?
I have tried to push in my "View 1" but then i first have to go back to my Detail View, before I can get the menu to show up...
I guess I have to make my "View 1" the root controller?
I recommend you to use segues. You can setup them in storyboard with Interface Builder. Just remember to use replace segues instead of push:
And the code:
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
switch (indexPath.row) {
case 0:
[self performSegueWithIdentifier:#"mainSegue" sender:self];
break;
case 1:
[self performSegueWithIdentifier:#"sheduleSegue" sender:self];
break;
case 2:
[self performSegueWithIdentifier:#"mapSegue" sender:self];
break;
}
}
Besides it, you can do some additional setup for each segue:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:#"mainSegue"]) {
TestViewController *dest = segue.destinationViewController;
dest.someNumber = 100500;
}
}

ipad Tabbar Customization Notworking

I want to Customize the tabbar of iPad. I have attached The image for Clarify my issue.
Currently My Tabbar Like this :
I want Like this.
I have Taken Custom Background Image for tabbar and using the following Code.
-(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
NSUInteger index=[[tabBarController viewControllers] indexOfObject:viewController];
switch (index)
{
case 0:
[_tabBarController.tabBar setBackgroundImage:[UIImage imageNamed:#"tab_act11.png"]];
break;
case 1:
[_tabBarController.tabBar setBackgroundImage:[UIImage imageNamed:#"tab_act22.png"]];
break;
case 2:
[_tabBarController.tabBar setBackgroundImage:[UIImage imageNamed:#"tab_act33.png"]];
break;
case 3:
[_tabBarController.tabBar setBackgroundImage:[UIImage imageNamed:#"tab_act44.png"]];
break;
case 4:
[_tabBarController.tabBar setBackgroundImage:[UIImage imageNamed:#"tab_act55.png"]];
break;
default:
break;
}
}
From the Above Code it It shows the tabbar as i want But , User interaction not working properly.I m unable to select Propertab.
You need to customize tabBarItem for each view controller not the whole tabBar at once.
For this you can use methods from UITabBarItem header. Following should help you:-
- (void)setFinishedSelectedImage:(UIImage *)selectedImage withFinishedUnselectedImage:(UIImage *)unselectedImage NS_AVAILABLE_IOS(5_0);
You can customize each viewController's tabBarItem using above, before adding them to the tabBarController.

How do I set action to alert view button (not so simple as that)

I am already trying it through the delegate method clickedButtonAtIndex: but I need to push a view through navigation controller as soon as the user presses "ok"...
I can't allocate the view inside the method, Xcode doesn't recognize the view controller's name in the code. Any idea what I'm coin wrong?
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
switch(buttonIndex) {
case 0:
ReminderCompleted *view = [[ReminderCompleted alloc]initWithNibName:#"ReminderCompleted" bundle:nil];
[view.navigationController pushViewController:view animated:NO];
break;
case 1:
//cancel
break;
default:
break;
}
I get some errors
You cannot push a view, you can only push view controllers. You should be able to structure the code in a similar fashion, but instantiate a view controller (which can also use a nib) instead, and pass that to the navigation controller's push method.
Edit: Your variable name confused me, and you are indeed using a view controller. My suspect now is declaring a new variable inside of a switch, which Objective-C does not like. Try the same code, but declare the variable before the switch (you can leave it uninitialized until the right case happens).
ReminderCompleted *reminderVC;
switch(buttonIndex) {
case 0:
reminderVC = [[ReminderCompleted alloc]initWithNibName:#"ReminderCompleted" bundle:nil];
[view.navigationController pushViewController:view animated:NO];
break;

Resources