iPadApp:i have a two classes TimeTableViewController and MLCViewController created a protocol in MLCViewController and that protocol i want to call in the TimeTableViewController . But the delegate(protocol) method is not calling in the TimeTableViewController.
Here is my code…….
In MLCViewController.h
//created protocol
#protocol MLCCancelDelegate;
#protocol MLCCancelDelegate <NSObject>
#optional
-(void)CancelMLCSession;
#end
#property(nonatomic,weak)id <MLCCancelDelegate>Mlcdelegate;
MLCViewController.m
//Which is written in a UIAlertView Delegate method
switch (buttonIndex) {
case 0:
{
if (self.Mlcdelegate && [self.Mlcdelegate respondsToSelector:#selector(CancelMLCSession)])
{
[self.Mlcdelegate CancelMLCSession];
}
break;
}
default:
break;
}
}
In TimeTableViewController.m
//ViewDidLoad
self.fifthViewController=[[MLCViewController alloc]init];
fifthViewController.Mlcdelegate = self;
//-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UIViewController* vc = [storyboard instantiateViewControllerWithIdentifier:#"MLCNote"];
pc = [[UIPopoverController alloc] initWithContentViewController:vc];
pc.delegate = self;
[pc presentPopoverFromRect:rect inView:collectionData
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
//Iam calling that delegate method like
-(void)CancelMLCSession{
NSLog(#"cancelling");
}
ADD this code
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
self.fifthViewController = [storyboard instantiateViewControllerWithIdentifier:#"MLCNote"];
pc = [[UIPopoverController alloc] initWithContentViewController:self.fifthViewController];
pc.delegate = self;
self.fifthViewController.Mlcdelegate=self;
Try putting
self. before fifthViewController.Mlcdelegate = self;
Try this,
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
MLCViewController* vc = (MLCViewController *)[storyboard instantiateViewControllerWithIdentifier:#"MLCNote"];
vc.Mlcdelegate = self;
self.fifthViewController = vc;
//rest stuff
Related
I would like to push to ParcelPickUpViewController after I clicked a button in LocationDetailsTableViewCell xib. But I've written the code below and it able to run. But the result won't happen at all. Need help on this issue. Thanks.
In LocationDetailsTableViewCell.h
#property (nonatomic, strong) UINavigationController *viewController;
In LocationDetailsTableViewCell.m
- (IBAction)selectBtn:(id)sender {
UIStoryboard *mainStoryBoard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
ParcelPickUpViewController *vc = [mainStoryBoard instantiateViewControllerWithIdentifier: # "pickUpVC"];
[self.viewController pushViewController:vc animated: YES];
[self.viewController setNavigationBarHidden:YES animated:YES];
}
I think you have button in UITableViewCell.Now you want to navigate to next view from the button click.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"CustomCell";
CustomCell *cell = (CustomCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil) {
NSArray *nibObjects = [[NSBundle mainBundle] loadNibNamed:#"CustomCell" owner:nil options:nil];
cell = [nibObjects objectAtIndex:0];
}
cell.btnSelct.tag = indexPath.row;
[cell.btnSelct addTarget:self action:#selector(selectBtn:) forControlEvents:UIControlEventTouchUpInside];
return cell;
}
- (IBAction)selectBtn:(id)sender
{
//This is for XIB
ParcelPickUpViewController *vc = [[ParcelPickUpViewController alloc]initWithNibName:#"pickUpVC" bundle:nil];
//If you use storyboard
UIStoryboard *mainStoryBoard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
ParcelPickUpViewController *vc = [mainStoryBoard instantiateViewControllerWithIdentifier: #"parcelpickup"];
[self.viewController pushViewController:vc animated: YES];
}
Try This ...
- (IBAction)selectBtn:(id)sender {
ParcelPickUpViewController *vc = [[HomeScreenVC alloc]initWithNibName:#"pickUpVC" bundle:nil];
[self.viewController pushViewController:vc animated: YES];
[self.viewController setNavigationBarHidden:YES animated:YES];
}
option 2
you are created the Navigation controller not allocated the memory of your instance navigation controller, so do like
UIStoryboard *mainStoryBoard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
ParcelPickUpViewController *vc = [mainStoryBoard instantiateViewControllerWithIdentifier: # "pickUpVC"];
self.viewController = [[UINavigationController alloc] init];
[self.viewController pushViewController:vc animated: YES];
[self.viewController setNavigationBarHidden:YES animated:YES];
if you no need the setNavigationBarHidden then use like
option 3
UIStoryboard *mainStoryBoard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
ParcelPickUpViewController *vc = [mainStoryBoard instantiateViewControllerWithIdentifier: # "pickUpVC"];
[self presentViewController:vc animated:YES completion:nil];
(1) Make sure you have set the isInitialViewController(the first controller you want to display when app launch) in storyboard.
(2) If you did not add UINavigationController in storyboard, create it programeticaly and set it as rootViewController w.r.t your InitialViewController in app delegate didFinishLaunchingWithOptions.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
UIStoryboard *storyboard = storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:Nil];
UIViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:#"Your_First_View_Controller_Identifier"];
UINavigationController *rootNavigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
self.window.rootViewController = rootNavigationController;
return YES;
}
(3) While navigating to your ParcelPickUpViewController just simply add below code:
- (IBAction)selectBtn:(id)sender {
ParcelPickUpViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier: # "pickUpVC"];
[self.navigationController pushViewController:vc animated: YES];
}
I am making an replica of Scrumptous sample app (ios facebook sdk version - 3.10 ) using Storyboard approach
I am able to load user name and profile image correctly.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Do nothing for now
switch (indexPath.row) {
case 2:
if (!self.friendPickerController) {
self.friendPickerController = [[FBFriendPickerViewController alloc]
initWithNibName:nil bundle:nil];
// Set the friend picker delegate
self.friendPickerController.delegate = self;
self.friendPickerController.title = #"Select friends";
}
[self.friendPickerController loadData];
[self.navigationController pushViewController:self.friendPickerController
animated:true];
break;
}
}
With below approach we can instantiateViewController but we need a valid identifier
/*
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
UIViewController *vc = [sb instantiateViewControllerWithIdentifier:#"myViewController"];
[self presentViewController:vc animated:YES completion:NULL];
*/
Hi I am trying to push a view controller in viewDidLoad
I am using storyboard.
In ViewDidLoad, I am checking that user is login and he is created his profile.
if user is not logged in or he does not created his profile then pushing the another view controller for login/profile view.
The following code does not working.
- (void)viewDidLoad
if(USER_IS_LOGGED_IN)
{
if(USER_PROFILE_COMPLETED)
{
[self sendRequest];
}
else
{
//push profile view
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
ProfileViewController *profileViewController = (ProfileViewController *)[storyboard instantiateViewControllerWithIdentifier:#"ProfileView"];
profileViewController.isFromDealView = YES;
profileViewController.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:profileViewController animated:YES];
}
}
else
{
//push login view
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
LoginViewController *loginViewController = (LoginViewController *)[storyboard instantiateViewControllerWithIdentifier:#"LoginView"];
loginViewController.isFromDealView = YES;
loginViewController.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:loginViewController animated:YES];
}
}
why don't you create the segue from your viewController to the Login and Profile View Controller and use performSegueUsingIdentifier: and push the navigation Controller using prepareForSegue: method
- (void)viewDidLoad
{
if(USER_IS_LOGGED_IN)
{
if(USER_PROFILE_COMPLETED)
{
[self sendRequest];
}
else
{
//push profile view
[self performSegueWithIdentifier:#"profileSegue" sender:self] ;
}
}
else
{
//push login view
[self performSegueWithIdentifier:#"loginSegue" sender:self] ;
}
}
in prepareforsegue method
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"profileSegue"]) {
ProfileViewController *profileViewController = segue.destinationViewController;
profileViewController.isFromDealView = YES;
profileViewController.hidesBottomBarWhenPushed = YES;
}
else if([segue.identifier isEqualToString:#"loginSegue"]){
LoginViewController *loginViewController = segue.destinationViewController;
loginViewController.isFromDealView = YES;
loginViewController.hidesBottomBarWhenPushed = YES;
}
else{
//no segue to push
}
}
I am little confuse with your code but any way try this
- (void)viewDidLoad {
if(USER_IS_LOGGED_IN) {
if(USER_PROFILE_COMPLETED)
{
[self sendRequest];
}
else
{
//push profile view
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
ProfileViewController *profileViewController = (ProfileViewController *)[storyboard instantiateViewControllerWithIdentifier:#"ProfileView"];
profileViewController.isFromDealView = YES;
profileViewController.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:profileViewController animated:YES];
}
} else {
//push login view
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
LoginViewController *loginViewController = (LoginViewController *)[storyboard instantiateViewControllerWithIdentifier:#"LoginView"];
loginViewController.isFromDealView = YES;
loginViewController.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:loginViewController animated:YES];
}`
}
First of all, sorry for my English.
I'm trying to do an app for iPad with a navigation controller which pushes view controllers when a button "Next" is selected. But I also want to have a popover, called from a button in the nav bar, that allows the user to "jump" from one view controller to another, pushing it with the tableView:didSelectRowAtIndexPath: and the pushViewController:animated: methods, but it's not working.
Summary:
Tab bar -> switches between FirstViewController and SecondViewController (works just fine)
Nav bar (button Next) -> switches between SecondViewController, FirstSlideController and SecondSlideController (it's also good)
Popover -> user selects SecondViewController, FirstSlideController or SecondSlideController (here's the problem!)
Codes:
AppDelegate
UIViewController *viewController1 = [[FirstViewController alloc] initWithNibName:#"FirstViewController" bundle:nil];
UINavigationController *navigationController1 = [[UINavigationController alloc] initWithRootViewController:viewController1];
UIViewController *viewController2 = [[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil];
UINavigationController *navigationController2 = [[UINavigationController alloc] initWithRootViewController:viewController2];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = #[navigationController1, navigationController2];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
TableViewController(popover)'s didSelectRowAtIndexPath method:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.row == 0){
FirstSlideController *detailViewController = [[FirstSlideController alloc] initWithNibName:#"FirstSlideController" bundle:nil];
[self.navigationController pushViewController:detailViewController animated:YES];
}
else if(indexPath.row == 1){
SecondSlideController *detailViewController = [[SecondSlideController alloc] initWithNibName:#"SecondSlideController" bundle:nil];
[self.navigationController pushViewController:detailViewController animated:YES];
}
else{
SecondViewController *detailViewController = [[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil];
[self.navigationController pushViewController:detailViewController animated:YES];
}
}
SecondViewController (with delegate suggested by maros)
-(void) showPopover:(id) sender
{
TableViewController *PopoverView = [[TableViewController alloc] initWithNibName:#"TableViewController" bundle:nil];
self.popOver = [[UIPopoverController alloc] initWithContentViewController:PopoverView];
self.popOver.delegate = self;
[self.popOver presentPopoverFromBarButtonItem:self.navigationItem.leftBarButtonItem permittedArrowDirections: UIPopoverArrowDirectionUp animated: YES];
}
I tried to print self.navigationController and it says it's null. I'd appreciate any help.
Thank you.
Presnented UIPopoverController is not pushed on the navigation stack in the view controller from which it was presented. It is a separate view controller.
Therefore the navigationController inside the popover is nil.
What I would recommend you is to create a delegate MyNavigationPopoverDelegate (the class that creates a popover (PopoverController). Pass it's instance as an delegate to the TableViewController.
After users clicks on some button inside popover, call delegate's method to processes button clicks (myNavigationPopover:(UIPopoverController*)popover clickedButtonAtIndex:(NSInteger)buttonIndex).
Then maybe dismiss delegate?
and finally change navigation however you want! :)
#protocol MyNavigationPopoverDelegate
- (void) myNavigationPopover:(UIPopoverController*)popover clickedButtonAtIndex:(NSInteger)buttonIndex;
#end
#interface TableViewController : UITableVieController // your viewController in popover
... // your code
#property (nonatomic, weak) NSObject <MyNavigationPopoverDelegate> * delegate;
... // your code
#end
#implementation TableViewController
...
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self.delegate myNavigationPopover:self clickedButtonAtIndex:indexPath.row];
}
...
#end
// defines that SecondViewController implements the delegate's method
#interface SecondViewController <MyNavigationPopoverDelegate> : UIViewController
// your code
#end
// code where you presenting popover
#implementation SecondViewController
// This is the method that is executed after your button press and it is responsible for presenting a popover
- (void) presentPopover{
...
myPopover.delegate = self; // setting the delegate
[myPopover presentPopoverFromXXX ...]; // however you present it
...
}
- (void) myNavigationPopover:(UIPopoverController*)popover clickedButtonAtIndex:(NSInteger)buttonIndex
{
UINavigationController *currentNavigationController = ; // get the navigation controller from the tab bar
if(buttonIndex == 0){
FirstSlideController *detailViewController = [[FirstSlideController alloc] initWithNibName:#"FirstSlideController" bundle:nil];
[currentNavigationController pushViewController:detailViewController animated:YES];
}
else if(buttonIndex == 1){
SecondSlideController *detailViewController = [[SecondSlideController alloc] initWithNibName:#"SecondSlideController" bundle:nil];
[currentNavigationController pushViewController:detailViewController animated:YES];
}
else{
SecondViewController *detailViewController = [[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil];
[currentNavigationController pushViewController:detailViewController animated:YES];
}
}
#end;
I want to pass data between storyboard with tabBar and external xib .
I tried to use prepareforsegue but the method didn't call or if i define a segue this didn't recognize this .
my code is :
UIStoryboard *storyborad = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
UIViewController *view = [storyborad instantiateViewControllerWithIdentifier:#"<identifier>"];
[self.navigationController setNavigationBarHidden:YES];
[self.navigationController pushViewController:view animated:YES];
// [self performSegueWithIdentifier:#"try" sender:self]; // tried to use performSegueWithIdentifier but this recognize identifier
and the prepareforsegue method code :
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
BIDViewController *viewControllerView = segue.destinationViewController;
viewControllerView.isViewPushed=1;
NSLog(#"prepareForSegue");
Instead of this:
UIStoryboard *storyborad = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
UIViewController *view = [storyborad instantiateViewControllerWithIdentifier:#"<identifier>"];
[self.navigationController setNavigationBarHidden:YES];
[self.navigationController pushViewController:view animated:YES];
Try this:
UIStoryboard *storyborad = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
BIDViewController *view = [storyborad instantiateViewControllerWithIdentifier:#"myIdentifier"];
view.isViewPushed = 1;
[self.navigationController setNavigationBarHidden:YES];
[self.navigationController pushViewController:view animated:YES];