Tabbar application in iphone - iphone

i am making an application in which am creating 5 tabbars in iDocViewController view. the problem is that when we are shifting control from disclaimer viewcontroller to idocviewcontroller tabbar. how'll i set focus on idocviewcontroller tabbar. how'll i get rid of this

int desiredTabIndex = // the tab's index within tabBars.viewControllers array
tabBar.selectedIndex = desiredTabIndex;

Related

Tabbar Controller with swipe effect

I'm trying to do a Tabbar Controller like below effect:
By swiping an viewcontroller will redirect to next tab. How can we achieve this in iOS? Is there any other controls to do like this?
Just add UISwipeGestureRecognizer to your tabBarView controller and change your tabBar index after swipe.
swipeRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self
action:#selector(swipeMethod:)];
swipeRecognizer.direction = UISwipeGestureRecognizerDirectionRight | UISwipeGestureRecognizerDirectionLeft;
[self addGestureRecognizer:swipeRecognizer];
And my method to handle swipe is :
-(void)swipeMethod: (UISwipeGestureRecognizer *) sender
{
NSLog(#"Swipe!");
}
EDIT
Or you can use UIScrollView with paging enable and UIView to display your data.
Here is the tutorial you are looking for Tabbar Controller with swipte effect
There is a library for this on GitHub, it is called MGSwipeTabBarController and is designed to do exactly what you are looking for.
It is as simple as :
NSArray *viewControllers = . . . //your view controllers
MGSwipeTabBarController *swipeController = [[MGSwipeTabBarController alloc] initWithViewControllers:viewControllers];
Please Note that it is only compatible with iOS7 and + and that you'll still need to design your own tab bar that respond to scroll events using the MGSwipeTabBarControllerDelegateprotocol.
https://github.com/mglagola/MGSwipeTabBarController
https://github.com/nicklockwood/SwipeView
you can use this class to achieve your goal...
or else you have to make animation for tap on tabbar using following method,
[UIView transitionFromView:<#(UIView *)#> toView:<#(UIView *)#> duration:<#(NSTimeInterval)#> options:<#(UIViewAnimationOptions)#> completion:<#^(BOOL finished)completion#>]
If anyone is still looking you can find another implementation here on this youtube series
https://www.youtube.com/watch?v=3Xv1mJvwXok&list=PL0dzCUj1L5JGKdVUtA5xds1zcyzsz7HLj
Edit:
So to my knowledge and according to the video, the idea is that you'll want to use two UICollectionViews in one view controller. One collection view to display the content (apps) and the other for the horizontal navigation containing the categories.
To create the green 'highlight' bar you can use a UIView and adjust the height/width of the bar using constraints - heightAnchor/widthAnchor and add that to the navigation bar.
To get the bar moving with the distance the user will swipe, there is a method you can override to capture the horizontal scrolling called scrollViewDidScroll. From here you'll want to provide a variable from your the UIView's constraint (of type NSLayoutConstraint) to be able to update the x position of the UIView
override func scrollViewDidScroll(_ scrollView: UIScrollView)
{
print(scrollView.contentOffset.x)
menuBar.myGreenBarLeftConstraint.constant = scrollView.contentOffset.x / 4
//or however many categories you have
}

Scroll to top when tapping the status bar

I got a view controller (lets call it MainViewContoller) that's present 3 different tables (one in a time), user can tap a segment control to switch between those tables.
To present those 3 tables, MainViewContoller has 3 other view controllers (A, B and C), each has a UITableView as a subview and handle it's own data.
When a MainViewContoller is loaded, it initiate controllers A, B and C, and add their tableViews to it's view:
- (void)viewDidLoad {
[super viewDidLoad];
ViewControllerA *vcA = [ViewControllerA alloc] init];
[self.view addSubview:vcA.view];
ViewControllerB *vcB = [ViewControllerB alloc] init];
[self.view addSubview:vcB.view];
ViewControllerC *vcC = [ViewControllerC alloc] init];
[self.view addSubview:vcC.view];
}
So for example when user tap the segment control and choose A, the MainViewContoller hide tables B and C, and unhide table A. Something like this:
if (userTapOnA) {
self.viewControllerA.tableView.hidden = NO;
self.viewControllerB.tableView.hidden = YES;
self.viewControllerC.tableView.hidden = YES;
}
The problem:
When user tap the status bar I want that the current visible table will scroll to top.
This behavior is pretty basic and one gets it for free when using a regular view controller, but as you can see my view controller is not regular.
I suppose that by using other controllers view as MainViewContoller view I break the default behavior, so my MainViewContoller doesn't handle the status bar tap.
Someone got an idea how to solve that?
This is directly from the UIScrollView header file:
/* When the user taps the status bar, the scroll view beneath the
touch which is closest to the status bar will be scrolled to top, but
only if its scrollsToTop property is YES, its delegate does not
return NO from shouldScrollViewScrollToTop, and it is not already at
the top. On iPhone, we execute this gesture only if there's one
on-screen scroll view with scrollsToTop == YES. If more than one is
found, none will be scrolled. */
#property(nonatomic) BOOL scrollsToTop; // default is YES.
So in your case, set all scrollsToTop to NO, except the one you want to enable at that particular moment.
You should register your nested controllers as child controllers.
[self addChildViewController:vcA];
[self addChildViewController:vcB];
[self addChildViewController:vcC];
I'm not sure if this will help to solve your issue, but that's the right way to do it.

How to Animate Switching Buttons in Xcode?

I have a button on navigationbar called Map and List
When Map is pressed I do
- (IBAction)Map:(id)sender {
self.tabBarController.navigationItem.rightBarButtonItem =self.List;
[BNUtilitiesQuick AnimateSwitchingWithParent:SwitchViews From:theTable To:GoogleMapController.view];
}
- (IBAction)List:(id)sender {
self.tabBarController.navigationItem.rightBarButtonItem =self.Map;
[BNUtilitiesQuick AnimateSwitchingWithParent:SwitchViews From:GoogleMapController.view To:theTable];
}
Now, curiously, rather than setting self.tabBarController.navigationItem.rightBarButtonItem =self.Map; and make the button split in a jiffy, I think I would like to animate that switch.
How would I do so?
Also how would I animate pushing and poping view to navigation controller? How do I animate users switching tabBar item?
If you check out the UITabBar documentation: UITabBar
- (void)setItems:(NSArray *)items animated:(BOOL)animated
Try making an array of the new tab bar items you want, and set it to the UITabBar
// Assuming "tabBar" is a UITabBar, probably part of a UITabBarController
// Assuming "newItem" is a new UITabBarItem containing the new buttons you want
// animate in.
NSArray* newItemArray = [NSArray arrayWithObjects:newItem,nil];
[tabBar setItems:newItemArray animated:YES];
// This should work, and you can include more than just one new item for multiple
// buttons on the tab bar.
Hope that works for you!

Tab Bar controller is not accessible

I have created a tab based application for iphone. when the 1st tab presses a first view will present. this view contains a button, on pressing it another view loads.
Code is:
-(IBAction)buttonPressed: (id) sender
{
Cities *cv=[[Cities alloc] initWithNibName:#"Cities" bundle:nil];
cv.modalTransitionStyle=UIModalTransitionStyleCoverVertical;
[self presentModalViewController:cv animated:YES];
[cv release];
}
Now problem is that this view is loading in whole screen so that I am not able to access tab bar.
I have set the frame for this view and the view is loading in this frame,
-(void)viewWillAppear:(BOOL)animated
{
self.view.frame = CGRectMake(0, 0, self.view.frame.size.width, 400);
}
but in remaining part white screen is appearing means tab bar is not accessible.
I want that whatever will be load at any time tab bar should be always accessible.
Please help me out.
Add
cv.modalPresentationStyle = UIModalPresentationCurrentContext;
Have you tried using UINavigationController inside your tabbar to dig inside your UIViewControllers??
for Ref : Adding NavigationController to Tabbar
do you really need a viewController Class for what you are trying to display??
if der's no core functionality being used, i think it will be much easier with UIView.
Happy Coding :)

UITableView position

my app uses a tab bar with 2 navigation based views in which I am adding a custom view (a title bar) between the nav bar and the table view .
- (void)viewDidLoad {
[super viewDidLoad];
// load title bar controller
TitleBarViewController *tbar = [[TitleBarViewController alloc] init];
[tbar setTitleImage:[UIImage imageNamed:#"v2-une.png"]];
[self setTitleBar:tbar];
[tbar release];
// show title bar
[self.navigationController.view addSubview:self.titleBar.view];
....
When the application is launched with a default selected nav view, I use (void)viewDidAppearBOOL)animated to set the table view to a lower Y value so that the title bar is visible.
Where Y = 20 : 20 is the height of my title bar.
self.tableView.frame = CGRectMake(0, 20, 320, 347);
The problem is that when I select a row and push a detail view and hide the bottom bar to display a toolbar, things are messed up.
my title bar's height increases and becomes > 20 which I can't explain why.
Now when I go back to the main table view, its Y is decreased by 20 and sticked to the nav bar. My title ben then appears above the first cell of the table view.
If hit the 2 tab and then go back to the 1st tab, everything is re arranged like expected.
here are some pics to illustrate all that :
link text
can anyone help me figure out why is this happening please ?
may be I am putting my positioning code in the wrong event ?
Is is possible that the background to everything is black and the tableview is moving down exposing the background, as opposed to the black titleBar actually increasing in size? This makes some sense given that the problem goes away when the tableView moves back up.