I have 5 standalone table view controller nibs (with custom cell implementation) accessible through an another table view menu list (no storyboards)
The client desires to have all 5 nibs in tabs. So I need to get rid of the menu list and provide nibs in TABs .
how can I do this ?
First add this property to your AppDelegate.h
#property (strong, nonatomic) UITabBarController *tabBarController;
make a method to set the views and set up your tabbar like:
-(void)setViews
{
UIViewController *viewController1 = [[FirstViewController alloc] initWithNibName:#"FirstViewController" bundle:nil] ;
UIViewController *viewController2 = [[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil];
UIViewController *viewController3 = [[ThirdViewController alloc] initWithNibName:#"ThirdViewController" bundle:nil];
UIViewController *viewController4 = [[FourthViewController alloc] initWithNibName:#"FourthViewController" bundle:nil];
UIViewController *viewController5 = [[FifthViewController alloc] initWithNibName:#"FifthViewController" bundle:nil];
UINavigationController *navigationController1=[[UINavigationController alloc]initWithRootViewController:viewController1];
[navigationController1.navigationBar setBackgroundImage:[UIImage imageNamed:#"upwhitebg.png"] forBarMetrics:UIBarMetricsDefault];
UINavigationController *navigationController2=[[UINavigationController alloc]initWithRootViewController:viewController2];
[navigationController2.navigationBar setBackgroundImage:[UIImage imageNamed:#"upwhitebg.png"] forBarMetrics:UIBarMetricsDefault];
UINavigationController *navigationController3=[[UINavigationController alloc]initWithRootViewController:viewController3];
[navigationController3.navigationBar setBackgroundImage:[UIImage imageNamed:#"upwhitebg.png"] forBarMetrics:UIBarMetricsDefault];
UINavigationController *navigationController4=[[UINavigationController alloc]initWithRootViewController:viewController4];
[navigationController4.navigationBar setBackgroundImage:[UIImage imageNamed:#"upwhitebg.png"] forBarMetrics:UIBarMetricsDefault];
UINavigationController *navigationController5=[[UINavigationController alloc]initWithRootViewController:viewController5];
[navigationController5.navigationBar setBackgroundImage:[UIImage imageNamed:#"upwhitebg.png"] forBarMetrics:UIBarMetricsDefault];
[navigationController1.navigationBar setHidden:YES];
[navigationController2.navigationBar setHidden:YES];
[navigationController3.navigationBar setHidden:YES];
[navigationController4.navigationBar setHidden:YES];
[navigationController5.navigationBar setHidden:YES];
self.tabBarController = [[UITabBarController alloc] init];
[self.tabBarController.tabBar setBackgroundColor:[UIColor clearColor]];
self.tabBarController.tabBar.backgroundImage = [UIImage imageNamed:#"tabbar"];
[[[self tabBarController]tabBar]setSelectionIndicatorImage:[UIImage imageNamed:#"transparent.png"]];
[self.tabBarController setDelegate:self];
self.tabBarController.viewControllers = #[navigationController1, navigationController2,navigationController3,navigationController4,navigationController5];
self.window.rootViewController = self.tabBarController;
}
avoid the set images and setHidden if you don't want to or not want to make the custom navigation bar.
and call this method in your didFinishLaunchingWithOptions.
Now set up the delegate method for tabbar and you can set the custom images over there:
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
if (tabBarController.selectedIndex == 0)
{
self.tabBarController.tabBar.backgroundImage = [UIImage imageNamed:#"tabbar-1"];
}
else if (tabBarController.selectedIndex == 1)
{
self.tabBarController.tabBar.backgroundImage = [UIImage imageNamed:#"tabbar-2"];
}
else if (tabBarController.selectedIndex == 2)
{
self.tabBarController.tabBar.backgroundImage = [UIImage imageNamed:#"tabbar-3"];
}
else if (tabBarController.selectedIndex == 3)
{
self.tabBarController.tabBar.backgroundImage = [UIImage imageNamed:#"tabbar-4"];
}
else if (tabBarController.selectedIndex == 4)
{
self.tabBarController.tabBar.backgroundImage = [UIImage imageNamed:#"tabbar-5"];
}
}
I'd set it all up in the main nib/storyboard, but it's easier to show in code. You can create the view controllers in the usual way (again, nib or storyboard or code).
UITabBarController *tabBarController = [[UITabBarController alloc] init];
[tabBarController setViewControllers:#[vc1, vc2, vc3, vc4, vc5] animated:YES];
UIWindow *window = [[UIApplication sharedApplication] delegate].window;
[window setRootViewController:tabBarController];
Related
I have an app that has the following structure:
The main view controller is a tab bar view controller that has 4 tabs.
Users can only access these view controllers when they are logged in. When app launches, it loads it's initial view controller (the tab bar one), and then I check to see if user is authenticated. If it's not, I present a login view controller.
The problem I'm having is that when app launches, it's loading the tab bar controller and from that controller it presents the login view controller, but it does so with a small time window that shows the tab bar controller's view on the screen, before the login's view. I need to directly present the login view, from the tab bar controller, but without showing tab bar controller's view in that small time interval, as it's not user friendly.
I read some answers on stackoverflow about presenting the new view controller without animation, and that's what I'm doing, but the problem persists.
I hope I've been clear enough on the issue, if you need more information just let me know.
EDIT: I'm presenting the login view controller on applicationDidBecomeActive: on applicationDelegate.m
In app delegate, In didFinishLaunchingWithOptions,
In condition if login or not,
self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UIViewController *viewController =[storyboard instantiateViewControllerWithIdentifier:#"your identifier"];
self.window.rootViewController = viewController;
[self.window makeKeyAndVisible];
You should something like this when you have view controller in storyboard.
self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
FirstViewController *firstviewController = [storyboard instantiateViewControllerWithIdentifier:#"FirstViewController"];
SecondViewController *secondviewController = [storyboard instantiateViewControllerWithIdentifier:#"SecondViewController"];
firstviewController.tabBarItem.image = [UIImage imageNamed:#"24-around-7"];
firstviewController.tabBarItem.title = #"First";
secondviewController.tabBarItem.title = #"Second";
secondviewController.tabBarItem.image = [UIImage imageNamed:#"60-around-7"];
UITabBarController *tabBarController = [[UITabBarController alloc]init];
tabBarController.viewControllers = #[firstviewController,secondviewController];
self.window.rootViewController = tabBarController;
And in FirstViewController's viewDidAppear you should check for user logged in or not and present view controller.
BOOL loginStatus = [[NSUserDefaults standardUserDefaults] boolForKey:#"isLoggedIn"];
if(loginStatus == NO){
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
LoginViewController *loginViewcontroller = [storyboard instantiateViewControllerWithIdentifier:#"LoginViewController"];
[self presentViewController:loginViewcontroller animated:YES completion:nil];
}
After successful login just dismiss login view controller . If user logout just present the loginviewcontroller
CREATE NEW .H .M
(this is my code)
yourController.h and yourController.m
then open
yourcontroller.m
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self)
{
NSLog(#"initWithFrame");
[self setupPinPopUp];
}
return self;
}
-(void)setupPinPopUp{
UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
UIVisualEffectView *blurEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
blurEffectView.frame = CGRectMake(0, 66, kSCREEN_WIDTH, kSCREEN_HEIGHT-66);
blurEffectView.userInteractionEnabled = TRUE;
UITapGestureRecognizer *singleFingerTap =
[[UITapGestureRecognizer alloc] initWithTarget:self
action:#selector(handleSingleTap:)];
[blurEffectView addGestureRecognizer:singleFingerTap];
blurEffectView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self addSubview:blurEffectView];
UIView *popUpMainView = [[UIView alloc]initWithFrame:CGRectMake(kSCREEN_WIDTH/2-150, kSCREEN_HEIGHT/2-160, 300, 270)];
popUpMainView.backgroundColor = Clear;
[self addSubview:popUpMainView];
UIView *popUpInsideView = [[UIView alloc]initWithFrame:CGRectMake(kSCREEN_WIDTH/2-150, kSCREEN_HEIGHT/2-102, 300, 210)];
popUpInsideView.backgroundColor = White;
popUpInsideView.layer.cornerRadius = 2.0;
popUpInsideView.clipsToBounds = TRUE;
[self addSubview:popUpInsideView];
UIImageView *imgCircleView = [[UIImageView alloc]initWithFrame:CGRectMake(100, 0, 100, 100)];
imgCircleView.layer.cornerRadius = 50;
imgCircleView.backgroundColor = White;
imgCircleView.clipsToBounds = TRUE;
[popUpMainView addSubview:imgCircleView];
UIImageView *imgInnerCircleView = [[UIImageView alloc]initWithFrame:CGRectMake(25, 8, 50, 50)];
imgInnerCircleView.backgroundColor = Clear;
imgInnerCircleView.image = [UIImage imageNamed:#"support"];
[imgCircleView addSubview:imgInnerCircleView];
UILabel *lblHeading = [[UILabel alloc]initWithFrame:CGRectMake(0, 20, popUpMainView.frame.size.width, 45)];
lblHeading.text = #"CUSTOMER SUPPORT";
lblHeading.numberOfLines = 0;
lblHeading.textColor = Black;
lblHeading.textAlignment = NSTextAlignmentCenter;
lblHeading.font = [UIFont fontWithName:#"HelveticaNeue-Bold" size:21];
[popUpInsideView addSubview:lblHeading];
UIButton *btnPhoneNumber = [[UIButton alloc]initWithFrame:CGRectMake(0, lblHeading.frame.size.height+lblHeading.frame.origin.y+10, popUpMainView.frame.size.width, 45)];
[btnPhoneNumber setTitle:#"18002345678" forState:UIControlStateNormal];
[btnPhoneNumber setTitleColor:Black forState:UIControlStateNormal];
btnPhoneNumber.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
btnPhoneNumber.titleLabel.font = [UIFont fontWithName:#"HelveticaNeue-Bold" size:18];
[btnPhoneNumber addTarget:self action:#selector(callSupport:) forControlEvents:UIControlEventTouchUpInside];
[popUpInsideView addSubview:btnPhoneNumber];
UIButton *btnEmail = [[UIButton alloc]initWithFrame:CGRectMake(0, btnPhoneNumber.frame.size.height+btnPhoneNumber.frame.origin.y+10, popUpMainView.frame.size.width, 45)];
[btnEmail setTitle:#"support#vurify.com" forState:UIControlStateNormal];
[btnEmail setTitleColor:Black forState:UIControlStateNormal];
btnEmail.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
btnEmail.titleLabel.font = [UIFont fontWithName:#"HelveticaNeue-Bold" size:18];
[btnEmail addTarget:self action:#selector(emailSupport:) forControlEvents:UIControlEventTouchUpInside];
[popUpInsideView addSubview:btnEmail];
}
- (void)handleSingleTap:(UITapGestureRecognizer *)recognizer {
[self removeFromSuperview];
}
-(IBAction)callSupport:(id)sender{
NSString *phoneNumber = [#"tel://" stringByAppendingString:#"180023456789"];
//[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber] options:#{} completionHandler:^(BOOL success)
{
if (success) {
NSLog(#"Opened url");
}
}];
}
-(IBAction)emailSupport:(id)sender{
[self removeFromSuperview];
}
//call the method like this wherever you want to call
//IN APP DELEGATE
UIView *rectView;
- (void)applicationWillEnterForeground:(UIApplication *)application
{
[rectView removeFromSuperview];
rectView = [[VurifyAppValidation alloc] initWithFrame:CGRectMake(0, 0, kSCREEN_WIDTH, kSCREEN_HEIGHT)];
[self.window addSubview:rectView];
}
I'm trying to change views within an app I am editing the code for. But the navigation bar doesn't seem to update in specific instances when presenting a new viewcontroller. Right now the behavior looks like this:
I navigate to a tableviewcontroller by clicking on a tab in the tabbar,
then I navigate to a viewcontroller from this tableviewcontroller using:
settingsController = [SettingsController create];
[self.navigationController pushViewController: settingsController animated: YES];
which I believe calls this code:
+(id)create
{
SettingsController*settings = [[SettingsController alloc] init];
NSBundle*bundle = [NSBundle bundleForClass: [SettingsController class]];
[bundle loadNibNamed: #"SettingsController" owner: settings options: NULL];
settings.view.frame = CGRectMake(0, 0, 320, 411);
settings.title = #"Settings";
return settings;
}
Then from there I navigate to another view controller using:
SearchViewController*searchView;
searchView = [[SearchViewController alloc] initWithNibName:#"SearchView" bundle: [NSBundle mainBundle]];
[self presentViewController:searchView animated:YES completion:nil];
and this is where the behavior starts getting buggy, the navigation bar doesnt update to the change in the view controller. I didn't write this code but it has been giving me a headache trying to clean it up.
If you are using a navigationController then you shouldn't call
[self presentViewController:searchView animated:YES completion:nil];.
You should use
[self.navigationController pushViewController:searchView animated:YES];
Also, it would be better to use the standard in-built function to initialize a new view controller.
SettingsController*settings = [[SettingsController alloc] initWithNibName:#"SettingsController" bundle:nil];
[self.navigationController pushViewController:settings animated:YES];
and then use the default method in the view controller.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.title = #"Settings";
//other view changes.
}
return self;
}
See this example for the way of initializing tabbarcontroller with navigation controller
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIViewController *viewController1, *viewController2,*viewController3;
viewController1 = [[ViewController alloc] init];
viewController2 = [[FormStatusViewController alloc] initWithNibName:#"FormStatusViewController" bundle:nil];
viewController3 = [[DocumentsViewController alloc] init];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:viewController1];
UINavigationController *nav1 =[[UINavigationController alloc] initWithRootViewController:viewController2];
UINavigationController *nav2 =[[UINavigationController alloc] initWithRootViewController:viewController3];
nav.navigationBarHidden=YES;
nav1.navigationBarHidden=YES;
nav2.navigationBarHidden=YES;
NSArray *viewsArray = [[NSArray alloc] initWithObjects:nav,nav1,nav2, nil];
self.formTabBar= [[UITabBarController alloc] init];
[self.formTabBar setViewControllers:viewsArray];
UITabBar *tabBar = self.formTabBar.tabBar;
UITabBarItem *tabBarItem1 = [tabBar.items objectAtIndex:0];
UITabBarItem *tabBarItem2 = [tabBar.items objectAtIndex:1];
UITabBarItem *tabBarItem3 = [tabBar.items objectAtIndex:2];
tabBarItem1.title = #"FORM";
tabBarItem2.title = #"STATUS";
tabBarItem3.title = #"DOCUMENTS";
UIImage *tabBackground = [[UIImage imageNamed:#"tab_bg.png"]
resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
[[UITabBar appearance] setBackgroundImage:tabBackground];
if ([[[UIDevice currentDevice] systemVersion] floatValue] < 7) {
[tabBarItem1 setFinishedSelectedImage:[UIImage imageNamed:#"form.png"] withFinishedUnselectedImage:[UIImage imageNamed:#"form_h.png"]];
[tabBarItem2 setFinishedSelectedImage:[UIImage imageNamed:#"status.png"] withFinishedUnselectedImage:[UIImage imageNamed:#"status_h.png"]];
[tabBarItem3 setFinishedSelectedImage:[UIImage imageNamed:#"documents.png"] withFinishedUnselectedImage:[UIImage imageNamed:#"documents_h.png"]];
} else {
tabBarItem1.selectedImage = [[UIImage imageNamed:#"form_h.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ];
tabBarItem1.image = [[UIImage imageNamed:#"form.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ];
tabBarItem2.selectedImage = [[UIImage imageNamed:#"status_h.png"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ];
tabBarItem2.image = [[UIImage imageNamed:#"status.png"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ];
tabBarItem3.selectedImage = [[UIImage imageNamed:#"documents_h.png"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ];
tabBarItem3.image = [[UIImage imageNamed:#"documents.png"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ];
}
[[UITabBar appearance] setSelectionIndicatorImage:
[UIImage imageNamed:#"tab_select_indicator.png"]];
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor], UITextAttributeTextColor,
nil] forState:UIControlStateNormal];
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor], UITextAttributeTextColor,
nil] forState:UIControlStateHighlighted];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = self.formTabBar;
[self.window makeKeyAndVisible];
return YES;
}
Now in your view controller suppose the firstviewcontroller in first tab you want to navigate to another view controller in that tab then use below code
SearchViewcontroller *searchView =[[SearchViewcontroller alloc]init];
[self.navigationController pushViewController:searchView animated:YES];
my original app had 5 home screen views and buttons in the home screens would open different other views.
i am not using storyboards. orignally there were no tabs in the app. then i added tabs to display the home screen using
UIViewController *viewController1 = [[FirstViewController alloc] initWithNibName:#"FirstViewController" bundle:nil] ;
UIViewController *viewController2 = [[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil];
UIViewController *viewController3 = [[ThirdViewController alloc] initWithNibName:#"ThirdViewController" bundle:nil];
UIViewController *viewController4 = [[FourthViewController alloc] initWithNibName:#"FourthViewController" bundle:nil];
UIViewController *viewController5 = [[FifthViewController alloc] initWithNibName:#"FifthViewController" bundle:nil];
UINavigationController *navigationController1=[[UINavigationController alloc]initWithRootViewController:viewController1];
[navigationController1.navigationBar setBackgroundImage:[UIImage imageNamed:#"upwhitebg.png"] forBarMetrics:UIBarMetricsDefault];
UINavigationController *navigationController2=[[UINavigationController alloc]initWithRootViewController:viewController2];
[navigationController2.navigationBar setBackgroundImage:[UIImage imageNamed:#"upwhitebg.png"] forBarMetrics:UIBarMetricsDefault];
UINavigationController *navigationController3=[[UINavigationController alloc]initWithRootViewController:viewController3];
[navigationController3.navigationBar setBackgroundImage:[UIImage imageNamed:#"upwhitebg.png"] forBarMetrics:UIBarMetricsDefault];
UINavigationController *navigationController4=[[UINavigationController alloc]initWithRootViewController:viewController4];
[navigationController4.navigationBar setBackgroundImage:[UIImage imageNamed:#"upwhitebg.png"] forBarMetrics:UIBarMetricsDefault];
UINavigationController *navigationController5=[[UINavigationController alloc]initWithRootViewController:viewController5];
[navigationController5.navigationBar setBackgroundImage:[UIImage imageNamed:#"upwhitebg.png"] forBarMetrics:UIBarMetricsDefault];
UITabBarController *tabBarController= [[UITabBarController alloc] init];
tabBarController.viewControllers = #[navigationController1, navigationController2,navigationController3,navigationController4,navigationController5];
//self.window.rootViewController = self.tabBarController;
UIWindow *window = [[UIApplication sharedApplication] delegate].window;
[window addSubview:tabBarController.view]
;
but now when i click the buttons on the homescreen how do i show the views which are outside the tabs ? and how do i comeback from that view to the 5 homescreen tab view.
earlier i was using this code to show the views on button press
listController = [[MenuListController alloc] initWithNibName:#"MenuListController" bundle:nil];
SUP101AppDelegate *delegate6 = [[UIApplication sharedApplication] delegate];
[delegate6.navController pushViewController:listController animated:YES]
You can launch other viewControllers by simply presenting them on the tabController now.
listController = [[MenuListController alloc] initWithNibName:#"MenuListController" bundle:nil];
SUP101AppDelegate *delegate6 = [[UIApplication sharedApplication] delegate];
[self.tabBarController presentViewController:listController animated:YES completion:nil];
you should also set the tabController to be window RootViewController
self.window.rootViewController = tabBarController;
//[window addSubview:tabBarController.view]
I'm working on an app and I face a problem with UINavigationcontroller.
First in the app delegate I check if the user is logged in, if so I take him to Main screen, if notI take him to the login screen.
This is my code:
UINavigationController *diabetesNavigationController = [UINavigationController alloc];
LoginViewController *loginPage = [[LoginViewController alloc]initWithNibName:#"LoginViewController" bundle:nil];
MainViewController *mainPage = [[MainViewController alloc]initWithNibName:#"MainViewController" bundle:nil];
if ([DataStore instance].userIsLoggedIn)
diabetesNavigationController = [diabetesNavigationController initWithRootViewController:mainPage];
else
diabetesNavigationController = [diabetesNavigationController initWithRootViewController:loginPage];
NSDictionary *navbarTitleTextAttributes = [NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:NSForegroundColorAttributeName];
[[UINavigationBar appearance]setBarTintColor:[UIColor orangeColor]];
[[UINavigationBar appearance]setTintColor:[UIColor whiteColor]];
[[UINavigationBar appearance]setTitleTextAttributes:navbarTitleTextAttributes];
[self.window setRootViewController:diabetesNavigationController];
The problem when the user logs out, he goes back to loginscreen but without the navigationcontroller.
I made something in MainViewController, which is this:
-(void)viewDidAppear:(BOOL)animated
{
self.navigationItem.title = #"Diabetes";
UIBarButtonItem *settingButton=[[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:#"burger.png"]
style:UIBarButtonItemStylePlain
target:self
action:#selector(onBurger:)];
self.navigationItem.rightBarButtonItem = settingButton;
self.navigationItem.leftBarButtonItem.enabled = YES;
}
So when I logout the user, with this code:
LoginViewController *loginPage = [[LoginViewController alloc]initWithNibName:#"LoginViewController" bundle:nil];
[self.navigationController setViewControllers:[NSArray arrayWithObjects:loginPage, nil] animated:YES];
I get to the login screen but without Navigationcontroller. I tried to set Hidden property to NO in all view delegates, but it still has this issue.
You can try this:
UIWindow *window = [UIApplication sharedApplication].keyWindow;
LoginViewController * loginPage = [[LoginViewController alloc] initWithNibName:#"LoginViewController" bundle:nil];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController: loginPage];
[window.rootViewController presentViewController:nav animated:YES completion:NULL];
Let me know if it works.. :)
I am new in iOS programming.
What I am trying to do is:
I have some views in a storyboard and I'd like to switch between the views programatically. For example, when a button is clicked, I call a method and I want to change views here (I can call the method successfully). The buttons are also created programatically in different positions.
I have searched and I think it happens with NavigationController. I have a navigation controller which I created like so: menu Editor -> Embed In -> NavigationController. How could I do this using this NavigationController?
#Madhu and #Dilip ,I found a solution with xib filed class
icerik *secondViewController = [[icerik alloc] initWithNibName:#"icerik" bundle:nil];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:secondViewController];
navigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;
navigationController.topViewController.title = #"SecondViewController";
//[self presentModalViewController:navigationController animated:YES];
if([self respondsToSelector:#selector(presentViewController:animated:completion:)])
[self presentViewController:navigationController animated:YES completion:^{/* done */}];
else if([self respondsToSelector:#selector(presentViewController:animated:)])
[self presentModalViewController:navigationController animated:YES];
I have a class with xib file named icerik, I solved it like this. It is opening but when I want to turn back, What can I do it ?
You can create btn using this code:
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self action:#selector(aMethod) forControlEvents:UIControlEventTouchDown];
[button setTitle:#"Show View" forState:UIControlStateNormal];
button.frame = CGRectMake(80.0, 210.0, 160.0, 40.0);
[self.view addSubview:button];
and for going to another vc use this code,if you want navigation bar:
-(void)aMethod
{
SecondViewController *secondViewController = [[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:SecondViewController];
navigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;
navigationController.topViewController.title = #"SecondViewController";
[self presentModalViewController:navigationController animated:YES];
}
Else use this code:
-(void)aMethod
{
SecondViewController *secondViewController = [[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil];
[self presentModalViewController:secondViewController animated:YES];
}
And for come back to frist vc fromm second vc add this code in second vc.
- (void)viewDidLoad
{
[super viewDidLoad];
UIBarButtonItem *closeButton = [[UIBarButtonItem alloc] initWithTitle:#"Back" style:UIBarButtonItemStyleBordered target:self action:#selector(backAction:)];
self.navigationItem.leftBarButtonItem = closeButton;
}
- (void)backAction:(id)sender {
[self dismissModalViewControllerAnimated:NO];
}
If your new to Objective-c first go with Views/ViewControllers. i.e. use addSubView property of UIView
UIView *subView = [[UIView alloc] initWithFrame:CGRectMake(10, 0, 250.0, kCCCellHeaderHeight)];
[subView setBackgroundColor:[UIColor redcolor]];
[self.view addSubview:subView];
If your little known of UINavigationCOntroller Use pushViewController
CCFilteredVideosController *filteredController = [[CCFilteredVideosController alloc] initWithNibName:#"CCFilteredVideosController" bundle:nil];
[self.navigationController pushViewController:filteredController animated:YES];
[filteredController release];