Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flyout unified First time event #70

Open
psmds opened this issue Feb 17, 2015 · 3 comments
Open

Flyout unified First time event #70

psmds opened this issue Feb 17, 2015 · 3 comments

Comments

@psmds
Copy link

psmds commented Feb 17, 2015

Flyout navigation has been working fine.But after I converted my code into unified. I got a problem in my app which contain login screen. after we login, the flyout navigation table view click(row click) is not working(unable to move next view controller) but if I went to new presentviewcontroller(i.e card.io) and come back its working fine.

Please find the below code.

I'm calling homeController from LoginController
using below code
Home homeObject=new Home();
this.NavigationController.PushViewController(this.homeObject,true);

Home

FlyoutNavigationController myflyout = new FlyoutNavigationController ();
UIView background = new UIView ();
background.ContentMode = UIViewContentMode.ScaleAspectFill;
background.Add (bg);

 UIImageView bg = new UIImageView (new CGRect (0f, 0f,

View.Bounds.Width, View.Bounds.Height));
bg.Image = imgBackground;
bg.ContentMode = UIViewContentMode.ScaleAspectFill;

 myflyout.NavigationTableView.BackgroundView = bg;
 myflyout.NavigationTableView.RowHeight = 44;
 myflyout.NavigationTableView.SectionIndexBackgroundColor =

UIColor.Clear;
myflyout.NavigationTableView.SectionIndexColor = UIColor.White;

 myflyout.NavigationTableView.SeparatorStyle =

UITableViewCellSeparatorStyle.None;
myflyout.NavigationTableView.SectionHeaderHeight = 20;
myflyout.NavigationTableView.Frame = new CGRect (0f, 250f,
View.Bounds.Width, View.Bounds.Height);
myflyout.NavigationTableView.TintColor = new UIColor (1, 1, 1, 1);

 myflyout.NavigationRoot = new RootElement ("Home") {
  new Section ()
  {
   GetMenuItem ("Single Item Payment", imgSinglePay),
   GetMenuItem ("Multi-items Payment", imgMultiPay),
   GetMenuItem ("Shopping Cart Setup", imgCartSetup),
   GetMenuItem ("Tax and Tips Setup", imgBillSettings),
   GetMenuItem ("History", imgHistory),
   GetMenuItem ("BitCoin History", imgHistory),
   GetMenuItem ("Reports", imgReports),
   GetMenuItem ("Settings", imgSettings),
   GetMenuItem("Business Logo",imgUpload),
   GetMenuItem ("Change Password", imgChangePassword),
   GetMenuItem ("Help", imgHelp),
   GetMenuItem ("Support", imgSupport),
   GetMenuItem ("Donate to charity", imgDonate),
   GetMenuItem ("Logout", imgLogout)
  }
 };


 myflyout.ViewControllers = new []
 {
  new MainPage (SellerToken, this, mailid, userid, flyout)as

UIViewController,

  new CartView (SellerToken, this, mailid, userid, flyout)as

UIViewController,
new AddCategory (flyout)as UIViewController,
new BuildSettings (flyout)as UIViewController,

  new History (username, password, this, mailid, CustomerID,

userorgid, flyout)as UIViewController,
new Bitcoinhistory (username, password, this, mailid, CustomerID,
userorgid, flyout)as UIViewController,
new SalesProductChart (flyout)as UIViewController,
new Debit_Settings (userid, username, password, phoneno, mailid,
dob, SellerToken, this, flyout)as UIViewController,
new UploadMerchantLogo (flyout)as UIViewController,
new Changepassword (username, this, flyout)as UIViewController,
new Debit_table_help (this, flyout)as UIViewController,
new Support (userid, mailid, phoneno, this, flyout),

  new DonateCharity(mailid,flyout)as UIViewController,

  new UINavigationController (new Loginpage (this, "logout"))
 };

 View.AddSubview (myflyout.View);
 View.Add (statusview);

please help me to solve this.

@Clancey @lubiluk @migueldeicaza @dvdsgl @timrisi

@hashbrown229
Copy link

I have the same problem. Once I login, and as i click on flyout button to navigate it shows me nullReferanceException.

Can anybody suggest the solution for this.

@psmds
Copy link
Author

psmds commented Jul 17, 2015

How you are adding flyout button? May be your flyout button will be null or your flyout navigation controller object will be null i.e yourflyoutobject.ToggleMenu() may be cause for null reference exception

Can you post your code(flyout part)?

@hashbrown229
Copy link

##MainController.cs

using System;
using System.Linq;
using System.Collections.Generic;

#if UNIFIED
using UIKit;
using Foundation;
#else
using MonoTouch.Foundation;
using MonoTouch.UIKit;
#endif
using MonoTouch.Dialog;
using FlyoutNavigation;

namespace GoodTVIOS
{
public class MainController : UIViewController
{
FlyoutNavigationController navigation;

// // Data we'll use to create our flyout menu and views:
string[] Tasks = {
"Get Xamarin",
"Learn C#",
"Write Killer App",
"Add Platforms",
"Profit",
"Meet Obama",
};

    public override void ViewDidLoad ()
    {
        base.ViewDidLoad ();

        // Create the flyout view controller, make it large,
        // and add it as a subview:
        navigation = new FlyoutNavigationController ();
        navigation.Position = FlyOutNavigationPosition.Right;
        navigation.View.Frame = UIScreen.MainScreen.Bounds;
        View.AddSubview (navigation.View);
        this.AddChildViewController (navigation);

        // Create the menu:
        navigation.NavigationRoot = new RootElement ("Extras") {
            new Section ("Task List") {
                from page in Tasks
                    select new StringElement (page) as Element
            },
            new Section ("Extras")
            {
                new BooleanElement("Toggle",true),
                new StringElement("Home Page"),
                new StringElement("Search"),
                //new BooleanElement("Toggle",true),
                //new StringElement("Profile"),
                //new StringElement("Swipable Table"),
            }
        };

        // Create an array of UINavigationControllers that correspond to your
        // menu items:
        var viewControllers = Tasks.Select (x => new UINavigationController (new TaskPageController (navigation, x))).ToList ();

        //Load from Storyboard
        var storyboardVc = CreateViewController<MyStoryboardViewController> ("MyStoryBoard", "MyStoryboardViewController");
        storyboardVc.navigation = navigation;
        viewControllers.Add (new UINavigationController(storyboardVc));

        //Add null for the toggle switch
        //viewControllers.Add (null);

// var ChannelVc = CreateViewController ("MyStoryBoard", "CHannelViewController");
// ChannelVc.navigation = navigation;
// viewControllers.Add (new UINavigationController (ChannelVc));

// viewControllers.Add (new UINavigationController(new SwipableTableView ()));

        var HomePVC = CreateViewController<HomePageViewController> ("MyStoryBoard", "HomePageViewController");
        HomePVC.navigation = navigation;
        viewControllers.Add (new UINavigationController (HomePVC));

        var SearchPVC = CreateViewController<SearchPageViewController> ("MyStoryBoard", "SearchPageViewController");
        SearchPVC.navigation = navigation;
        viewControllers.Add (new UINavigationController (SearchPVC));

        navigation.ViewControllers = viewControllers.ToArray ();

    }
    static T CreateViewController<T>(string storyboardName, string viewControllerStoryBoardId = "") where T : UIViewController
    {
        var storyboard = UIStoryboard.FromName (storyboardName,null);
        return string.IsNullOrEmpty(viewControllerStoryBoardId) ? (T)storyboard.InstantiateInitialViewController () : (T) storyboard.InstantiateViewController(viewControllerStoryBoardId);
    }
    class TaskPageController : DialogViewController
    {
        public TaskPageController (FlyoutNavigationController navigation, string title) : base (null)
        {
            Root = new RootElement (title) {
                new Section {
                    new CheckboxElement (title)
                }
            };
            NavigationItem.LeftBarButtonItem = new UIBarButtonItem (UIBarButtonSystemItem.Action, delegate {
                navigation.ToggleMenu ();
            });
        }
    }
}

}

$$HomePageViewController.cs

using Foundation;
using System;
using System.CodeDom.Compiler;
using UIKit;
using FlyoutNavigation;
namespace GoodTVIOS
{
partial class HomePageViewController : UIViewController
{
public FlyoutNavigationController navigation { get; set; }
public HomePageViewController (IntPtr handle) : base (handle)
{
}

    public HomePageViewController()
    {
        NavigationItem.LeftBarButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Action, delegate
            {
                navigation.ToggleMenu();
            });
    }

    public override void ViewWillAppear(bool animated)
    {
        base.ViewWillAppear(animated);
        NavigationItem.LeftBarButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Action, delegate
            {
                navigation.ToggleMenu();
            });
    }
}

}

$$AppDelegates.cs

using System;
using System.Linq;
using System.Collections.Generic;

#if UNIFIED
using UIKit;
using Foundation;
#else
using MonoTouch.Foundation;
using MonoTouch.UIKit;
#endif
using MonoTouch.Dialog;

using FlyoutNavigation;

namespace GoodTVIOS
{
[Register ("AppDelegate")]
public partial class AppDelegate : UIApplicationDelegate
{
UIWindow window;

    public override bool FinishedLaunching (UIApplication app, NSDictionary options)
    {
        window = new UIWindow (UIScreen.MainScreen.Bounds) {
            RootViewController = new MainController ()
        };
        window.MakeKeyAndVisible ();
        return true;
    }
}

}

$$MyStoryboardViewContoller.cs

using System;
#if UNIFIED
using Foundation;
using UIKit;
#else
using MonoTouch.Foundation;
using MonoTouch.UIKit;
#endif
using System.CodeDom.Compiler;
using FlyoutNavigation;
using Utilities;

namespace GoodTVIOS
{
partial class MyStoryboardViewController : UIViewController
{
public FlyoutNavigationController navigation { get; set; }

    UtilitiesClass util;
    public MyStoryboardViewController (IntPtr handle) : base (handle)
    {
    }

    public MyStoryboardViewController()
    {
        NavigationItem.LeftBarButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Action, delegate
            {
                navigation.ToggleMenu();
            });
    }

    public override void ViewDidLoad ()
    {
        base.ViewDidLoad ();
        util = new UtilitiesClass ();
        //email = dev.intern@creationfilms.com
        //pass =intern20152
        txtUname.Text = "dev.intern@creationfilms.com";
        txtPass.Text = "intern20152";
    }

    partial void btnLogin_TouchUpInside (UIButton sender)
    {
        Console.WriteLine("btnLogin_TouchUpInside");
        string status="";
        string response="";
        util.UserLogin(txtUname.Text,txtPass.Text,out status,out response);
        Console.WriteLine("status "+status);
        //controller.UserName = txtPass.Text;


        if (status=="OK")
        {
            HomePageViewController HomePVC = this.Storyboard.InstantiateViewController("HomePageViewController")
                as HomePageViewController;
            this.NavigationController.PushViewController(HomePVC, true);

// CHannelViewController channel =this.Storyboard.InstantiateViewController("CHannelViewController")
// as CHannelViewController;
// channel.UserName = txtUname.Text;
// this.NavigationController.PushViewController(channel,true);

        }

        if (status=="DOWN")
        {
            new UIAlertView("Alert", "Email/Password is Incorrect", null, "OK", null).Show();
        }
    }


    public override void ViewWillAppear(bool animated)
    {
        base.ViewWillAppear(animated);
        NavigationItem.LeftBarButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Action, delegate
        {
            navigation.ToggleMenu();
        });
    }
}

}

Here's my code. Please let me know the solution.

screen shot 2015-07-22 at 10 40 22 am

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants