iOS中MonoTouch.SlideoutNavigation中的注销问题(Xamarin)
我是iOS的新手。我正在使用Xamarin下面的组件创建幻灯片导航菜单。Github链接在下面 链接:iOS中MonoTouch.SlideoutNavigation中的注销问题(Xamarin),ios,xamarin.ios,navigation,Ios,Xamarin.ios,Navigation,我是iOS的新手。我正在使用Xamarin下面的组件创建幻灯片导航菜单。Github链接在下面 链接: var loginViewController = storyboard.InstantiateViewController("ViewController") as ViewController; BizApplication.clearCredential(); StyledStringElement logout = new StyledStringElement("Logout", (
var loginViewController = storyboard.InstantiateViewController("ViewController") as ViewController;
BizApplication.clearCredential();
StyledStringElement logout = new StyledStringElement("Logout", () => NavigationController.PushViewController(loginViewController, true)){ TextColor = UIColor.White, BackgroundColor = UIColor.Clear };
logout.Image = new UIImage("filter_icon.png");
在这个组件中,整个组件工作正常。但我有一个小问题
最初,我的LoginViewController
是这样的
屏幕截图:
var loginViewController = storyboard.InstantiateViewController("ViewController") as ViewController;
BizApplication.clearCredential();
StyledStringElement logout = new StyledStringElement("Logout", () => NavigationController.PushViewController(loginViewController, true)){ TextColor = UIColor.White, BackgroundColor = UIColor.Clear };
logout.Image = new UIImage("filter_icon.png");
左侧没有菜单按钮
现在当我登录新打开的屏幕时,菜单是这样的
屏幕截图:
var loginViewController = storyboard.InstantiateViewController("ViewController") as ViewController;
BizApplication.clearCredential();
StyledStringElement logout = new StyledStringElement("Logout", () => NavigationController.PushViewController(loginViewController, true)){ TextColor = UIColor.White, BackgroundColor = UIColor.Clear };
logout.Image = new UIImage("filter_icon.png");
现在,当打开滑出菜单并选择注销
选项时,我想启动我的LoginViewController
它也可以使用下面的代码正常工作
代码:
var loginViewController = storyboard.InstantiateViewController("ViewController") as ViewController;
BizApplication.clearCredential();
StyledStringElement logout = new StyledStringElement("Logout", () => NavigationController.PushViewController(loginViewController, true)){ TextColor = UIColor.White, BackgroundColor = UIColor.Clear };
logout.Image = new UIImage("filter_icon.png");
但现在我在屏幕下,这是不想要的。我想删除导航中的左侧菜单图标
屏幕截图:
var loginViewController = storyboard.InstantiateViewController("ViewController") as ViewController;
BizApplication.clearCredential();
StyledStringElement logout = new StyledStringElement("Logout", () => NavigationController.PushViewController(loginViewController, true)){ TextColor = UIColor.White, BackgroundColor = UIColor.Clear };
logout.Image = new UIImage("filter_icon.png");
任何帮助都将不胜感激
更新:
打开新控制器的推送代码:
if (BizApplication.getCredential() != null)
{
window = new UIWindow(UIScreen.MainScreen.Bounds);
Menu = new SlideoutNavigationController();
var webController2 = Storyboard.InstantiateViewController("SearchViewController") as SearchViewController;
NavigationController.PushViewController(webController2, true);
Menu.MainViewController = new MainNavigationController(webController2, Menu);
Menu.MenuViewController = new MenuNavigationController(new DummyControllerLeft(), Menu) { NavigationBarHidden = true };
window.RootViewController = Menu;
window.MakeKeyAndVisible();
loadingOverlay.Hide();
}
我的流量:
var loginViewController = storyboard.InstantiateViewController("ViewController") as ViewController;
BizApplication.clearCredential();
StyledStringElement logout = new StyledStringElement("Logout", () => NavigationController.PushViewController(loginViewController, true)){ TextColor = UIColor.White, BackgroundColor = UIColor.Clear };
logout.Image = new UIImage("filter_icon.png");
我的项目只使用了一个故事板。因此,所有ViewController都在同一个故事板中
部署信息:
var loginViewController = storyboard.InstantiateViewController("ViewController") as ViewController;
BizApplication.clearCredential();
StyledStringElement logout = new StyledStringElement("Logout", () => NavigationController.PushViewController(loginViewController, true)){ TextColor = UIColor.White, BackgroundColor = UIColor.Clear };
logout.Image = new UIImage("filter_icon.png");
AppDelegate.cs我不会更改此文件中的任何内容
SplashViewController.cs
public partial class SplashViewController : UIViewController
{
UIWindow window;
UIViewController container;
UIStoryboard storyboard;
public SlideoutNavigationController Menu { get; private set; }
public SplashViewController(IntPtr handle) : base(handle)
{
}
public override void ViewDidLoad()
{
base.ViewDidLoad();
if (Reachability.IsHostReachable("http://google.com"))
{
if (BizApplication.CheckCredential())
{
window = new UIWindow(UIScreen.MainScreen.Bounds);
Menu = new SlideoutNavigationController();
storyboard = UIStoryboard.FromName("Main", null);
var webController = storyboard.InstantiateViewController("SearchViewController") as SearchViewController;
NavigationController.PushViewController(webController, true);
Menu.MainViewController = new MainNavigationController(webController, Menu);
Menu.MenuViewController = new MenuNavigationController(new DummyControllerLeft(), Menu) { NavigationBarHidden = true };
window.RootViewController = Menu;
window.MakeKeyAndVisible();
}
else {
storyboard = UIStoryboard.FromName("Main", null);
var webController = storyboard.InstantiateViewController("ViewController") as ViewController;
this.NavigationController.PushViewController(webController, true);
}
}
}
public void pushMenu()
{
UINavigationController navMin = (UINavigationController)window.RootViewController;
Menu = new SlideoutNavigationController();
storyboard = UIStoryboard.FromName("Main", null);
var webController = storyboard.InstantiateViewController("SearchViewController") as SearchViewController;
Menu.MainViewController = new MainNavigationController(webController, Menu);
Menu.MenuViewController = new MenuNavigationController(new DummyControllerLeft(), Menu) { NavigationBarHidden = true };
navMin.PushViewController(Menu, true);
}
}
using System;
using System.Drawing;
using System.Threading.Tasks;
using CoreAnimation;
using Foundation;
using Gargi.Business;
using MonoTouch.Dialog;
using UIKit;
namespace Gargi.iOS
{
public class DummyControllerLeft : DialogViewController
{
public static UIImageView profileImage;
public DummyControllerLeft(IntPtr handle) : base(handle)
{
}
public DummyControllerLeft()
: base(UITableViewStyle.Plain, new RootElement(""))
{
var storyboard = UIStoryboard.FromName("Main", null);
var webController = storyboard.InstantiateViewController("SearchViewController") as SearchViewController;
StyledStringElement search = new StyledStringElement("Search", () => NavigationController.PushViewController(webController, true)) { TextColor = UIColor.White, BackgroundColor = UIColor.Clear };
search.Image = new UIImage("filter_icon.png");
var appointController = storyboard.InstantiateViewController("AppointmentListController") as AppointmentListController;
StyledStringElement appointment = new StyledStringElement("Appointment", () => NavigationController.PushViewController(appointController, true)) { TextColor = UIColor.White, BackgroundColor = UIColor.Clear };
appointment.Image = new UIImage("filter_icon.png");
var caseHistoryController = storyboard.InstantiateViewController("CaseHistoryController") as CaseHistoryController;
StyledStringElement casehistory = new StyledStringElement("CaseHistory", () => NavigationController.PushViewController(caseHistoryController, true)){ TextColor = UIColor.White, BackgroundColor = UIColor.Clear };
casehistory.Image = new UIImage("filter_icon.png");
var accountController = storyboard.InstantiateViewController("AccountViewController") as AccountViewController;
StyledStringElement account = new StyledStringElement("Account", () => NavigationController.PushViewController(accountController, true)){ TextColor = UIColor.White, BackgroundColor = UIColor.Clear };
account.Image = new UIImage("filter_icon.png");
var securityController = storyboard.InstantiateViewController("SecurityViewController") as SecurityViewController;
StyledStringElement security = new StyledStringElement("Security", () => NavigationController.PushViewController(securityController, true)){ TextColor = UIColor.White, BackgroundColor = UIColor.Clear };
security.Image = new UIImage("filter_icon.png");
var workProfileController = storyboard.InstantiateViewController("WorkProfileViewController") as WorkProfileViewController;
StyledStringElement workProfile = new StyledStringElement("WorkProfile", () => NavigationController.PushViewController(workProfileController, true)){ TextColor = UIColor.White, BackgroundColor = UIColor.Clear };
workProfile.Image = new UIImage("filter_icon.png");
BizApplication.clearCredential();
StyledStringElement logout = new StyledStringElement("Logout",() => CallthisMethod()){ TextColor = UIColor.White, BackgroundColor = UIColor.Clear };
logout.Image = new UIImage("filter_icon.png");
Root.Add(new Section()
{
search,
appointment,
casehistory,
account,
security,
workProfile,
logout
} );
TableView.SeparatorStyle = UITableViewCellSeparatorStyle.None;
TableView.BackgroundColor = UIColor.Clear.FromHexString("#0072BA", 1.0f);
}
void CallthisMethod()
{
var vwControllers = NavigationController.ViewControllers;
foreach (UIViewController signiinVC in vwControllers)
{
if (signiinVC.GetType() == typeof(ViewController))
{
this.NavigationController.PopToViewController(signiinVC,true);
}
}
}
public override void ViewDidLoad()
{
base.ViewDidLoad();
TableView.Frame = new RectangleF((float)TableView.Frame.Left, (float)(TableView.Frame.Top + 30), (float)TableView.Frame.Width, (float)(TableView.Frame.Height - 30));
UIView headerView = new UIView();
headerView.Frame = new CoreGraphics.CGRect(0, 0, TableView.Frame.Width, 140);
//headerView.BackgroundColor = UIColor.Clear.FromHexString("#004F80", 1.0f);
profileImage = new UIImageView();
profileImage.Frame = new CoreGraphics.CGRect(10, 10, 70, 70);
profileImage.Layer.CornerRadius = 35;
profileImage.ClipsToBounds = true;
profileImage.Image = UIImage.FromBundle("gargi_logo.png");
UILabel userName = new UILabel();
userName.Frame = new CoreGraphics.CGRect(10, 90, TableView.Frame.Width - 20, 20);
userName.Font = UIFont.FromName("Helvetica-Bold", 14f);
userName.TextColor = UIColor.White;
headerView.AddSubview(userName);
UILabel userRole = new UILabel();
userRole.Frame = new CoreGraphics.CGRect(10, 110, TableView.Frame.Width - 20, 20);
userRole.Font = UIFont.FromName("Helvetica-Bold", 14f);
userRole.TextColor = UIColor.White;
headerView.AddSubview(userRole);
headerView.AddSubview(profileImage);
TableView.TableHeaderView = headerView;
if (BizApplication.getCredential().Name != null)
{
userName.Text = BizApplication.getCredential().Name;
}
if (BizApplication.getCredential().Role != null)
{
userRole.Text = BizApplication.getCredential().Role;
}
var gradient = new CAGradientLayer();
gradient.Frame = headerView.Frame;
gradient.Colors = new CoreGraphics.CGColor[] { UIColor.Clear.FromHexString("#0072BA", 1.0f).CGColor,UIColor.Clear.FromHexString("#004f80",1.0f).CGColor};
headerView.Layer.InsertSublayer(gradient, 0);
var task = GetUserImage();
}
private async Task GetUserImage()
{
var userHeader = await UserClient.GetHeaderData();
if (!string.IsNullOrEmpty(userHeader.Image))
{
string trimbase = userHeader.Image.Trim('"');
try
{
var imageBytes = Convert.FromBase64String(trimbase);
var imageData = NSData.FromArray(imageBytes);
profileImage.BackgroundColor = UIColor.White;
profileImage.Layer.CornerRadius = 35;
profileImage.ClipsToBounds = true;
profileImage.Image = UIImage.LoadFromData(imageData);
}
catch (Exception ex)
{
string msg = ex.Message;
}
}
}
}
}
ViewController.cs(是我的登录视图控制器)
DummyControllerLeft.cs
public partial class SplashViewController : UIViewController
{
UIWindow window;
UIViewController container;
UIStoryboard storyboard;
public SlideoutNavigationController Menu { get; private set; }
public SplashViewController(IntPtr handle) : base(handle)
{
}
public override void ViewDidLoad()
{
base.ViewDidLoad();
if (Reachability.IsHostReachable("http://google.com"))
{
if (BizApplication.CheckCredential())
{
window = new UIWindow(UIScreen.MainScreen.Bounds);
Menu = new SlideoutNavigationController();
storyboard = UIStoryboard.FromName("Main", null);
var webController = storyboard.InstantiateViewController("SearchViewController") as SearchViewController;
NavigationController.PushViewController(webController, true);
Menu.MainViewController = new MainNavigationController(webController, Menu);
Menu.MenuViewController = new MenuNavigationController(new DummyControllerLeft(), Menu) { NavigationBarHidden = true };
window.RootViewController = Menu;
window.MakeKeyAndVisible();
}
else {
storyboard = UIStoryboard.FromName("Main", null);
var webController = storyboard.InstantiateViewController("ViewController") as ViewController;
this.NavigationController.PushViewController(webController, true);
}
}
}
public void pushMenu()
{
UINavigationController navMin = (UINavigationController)window.RootViewController;
Menu = new SlideoutNavigationController();
storyboard = UIStoryboard.FromName("Main", null);
var webController = storyboard.InstantiateViewController("SearchViewController") as SearchViewController;
Menu.MainViewController = new MainNavigationController(webController, Menu);
Menu.MenuViewController = new MenuNavigationController(new DummyControllerLeft(), Menu) { NavigationBarHidden = true };
navMin.PushViewController(Menu, true);
}
}
using System;
using System.Drawing;
using System.Threading.Tasks;
using CoreAnimation;
using Foundation;
using Gargi.Business;
using MonoTouch.Dialog;
using UIKit;
namespace Gargi.iOS
{
public class DummyControllerLeft : DialogViewController
{
public static UIImageView profileImage;
public DummyControllerLeft(IntPtr handle) : base(handle)
{
}
public DummyControllerLeft()
: base(UITableViewStyle.Plain, new RootElement(""))
{
var storyboard = UIStoryboard.FromName("Main", null);
var webController = storyboard.InstantiateViewController("SearchViewController") as SearchViewController;
StyledStringElement search = new StyledStringElement("Search", () => NavigationController.PushViewController(webController, true)) { TextColor = UIColor.White, BackgroundColor = UIColor.Clear };
search.Image = new UIImage("filter_icon.png");
var appointController = storyboard.InstantiateViewController("AppointmentListController") as AppointmentListController;
StyledStringElement appointment = new StyledStringElement("Appointment", () => NavigationController.PushViewController(appointController, true)) { TextColor = UIColor.White, BackgroundColor = UIColor.Clear };
appointment.Image = new UIImage("filter_icon.png");
var caseHistoryController = storyboard.InstantiateViewController("CaseHistoryController") as CaseHistoryController;
StyledStringElement casehistory = new StyledStringElement("CaseHistory", () => NavigationController.PushViewController(caseHistoryController, true)){ TextColor = UIColor.White, BackgroundColor = UIColor.Clear };
casehistory.Image = new UIImage("filter_icon.png");
var accountController = storyboard.InstantiateViewController("AccountViewController") as AccountViewController;
StyledStringElement account = new StyledStringElement("Account", () => NavigationController.PushViewController(accountController, true)){ TextColor = UIColor.White, BackgroundColor = UIColor.Clear };
account.Image = new UIImage("filter_icon.png");
var securityController = storyboard.InstantiateViewController("SecurityViewController") as SecurityViewController;
StyledStringElement security = new StyledStringElement("Security", () => NavigationController.PushViewController(securityController, true)){ TextColor = UIColor.White, BackgroundColor = UIColor.Clear };
security.Image = new UIImage("filter_icon.png");
var workProfileController = storyboard.InstantiateViewController("WorkProfileViewController") as WorkProfileViewController;
StyledStringElement workProfile = new StyledStringElement("WorkProfile", () => NavigationController.PushViewController(workProfileController, true)){ TextColor = UIColor.White, BackgroundColor = UIColor.Clear };
workProfile.Image = new UIImage("filter_icon.png");
BizApplication.clearCredential();
StyledStringElement logout = new StyledStringElement("Logout",() => CallthisMethod()){ TextColor = UIColor.White, BackgroundColor = UIColor.Clear };
logout.Image = new UIImage("filter_icon.png");
Root.Add(new Section()
{
search,
appointment,
casehistory,
account,
security,
workProfile,
logout
} );
TableView.SeparatorStyle = UITableViewCellSeparatorStyle.None;
TableView.BackgroundColor = UIColor.Clear.FromHexString("#0072BA", 1.0f);
}
void CallthisMethod()
{
var vwControllers = NavigationController.ViewControllers;
foreach (UIViewController signiinVC in vwControllers)
{
if (signiinVC.GetType() == typeof(ViewController))
{
this.NavigationController.PopToViewController(signiinVC,true);
}
}
}
public override void ViewDidLoad()
{
base.ViewDidLoad();
TableView.Frame = new RectangleF((float)TableView.Frame.Left, (float)(TableView.Frame.Top + 30), (float)TableView.Frame.Width, (float)(TableView.Frame.Height - 30));
UIView headerView = new UIView();
headerView.Frame = new CoreGraphics.CGRect(0, 0, TableView.Frame.Width, 140);
//headerView.BackgroundColor = UIColor.Clear.FromHexString("#004F80", 1.0f);
profileImage = new UIImageView();
profileImage.Frame = new CoreGraphics.CGRect(10, 10, 70, 70);
profileImage.Layer.CornerRadius = 35;
profileImage.ClipsToBounds = true;
profileImage.Image = UIImage.FromBundle("gargi_logo.png");
UILabel userName = new UILabel();
userName.Frame = new CoreGraphics.CGRect(10, 90, TableView.Frame.Width - 20, 20);
userName.Font = UIFont.FromName("Helvetica-Bold", 14f);
userName.TextColor = UIColor.White;
headerView.AddSubview(userName);
UILabel userRole = new UILabel();
userRole.Frame = new CoreGraphics.CGRect(10, 110, TableView.Frame.Width - 20, 20);
userRole.Font = UIFont.FromName("Helvetica-Bold", 14f);
userRole.TextColor = UIColor.White;
headerView.AddSubview(userRole);
headerView.AddSubview(profileImage);
TableView.TableHeaderView = headerView;
if (BizApplication.getCredential().Name != null)
{
userName.Text = BizApplication.getCredential().Name;
}
if (BizApplication.getCredential().Role != null)
{
userRole.Text = BizApplication.getCredential().Role;
}
var gradient = new CAGradientLayer();
gradient.Frame = headerView.Frame;
gradient.Colors = new CoreGraphics.CGColor[] { UIColor.Clear.FromHexString("#0072BA", 1.0f).CGColor,UIColor.Clear.FromHexString("#004f80",1.0f).CGColor};
headerView.Layer.InsertSublayer(gradient, 0);
var task = GetUserImage();
}
private async Task GetUserImage()
{
var userHeader = await UserClient.GetHeaderData();
if (!string.IsNullOrEmpty(userHeader.Image))
{
string trimbase = userHeader.Image.Trim('"');
try
{
var imageBytes = Convert.FromBase64String(trimbase);
var imageData = NSData.FromArray(imageBytes);
profileImage.BackgroundColor = UIColor.White;
profileImage.Layer.CornerRadius = 35;
profileImage.ClipsToBounds = true;
profileImage.Image = UIImage.LoadFromData(imageData);
}
catch (Exception ex)
{
string msg = ex.Message;
}
}
}
}
}
最新更新:
如果我在DummyLeftControllers.cs中执行此操作,则不会发生任何事情:
StyledStringElement logout = new StyledStringElement("Logout",() => CallthisMethod(storyboard)){ TextColor = UIColor.White, BackgroundColor = UIColor.Clear };
logout.Image = new UIImage("filter_icon.png");
void CallthisMethod(UIStoryboard storyboard)
{
var vwControllers = NavigationController.ViewControllers;
foreach (UIViewController signiinVC in vwControllers)
{
if (signiinVC.GetType() == typeof(ViewController))
{
this.NavigationController.PopToViewController(signiinVC, true);
}
}
BizApplication.clearCredential();
NavigationController.PopToRootViewController(true);
}
您在注销时在堆栈上按下SignInView控制器,这是不正确的。以使用以前从堆栈中推送的视图的方式编写代码 在Splashviewconrtroller中,在viewdidload方法中更改以下内容:
base.ViewDidUnload ();
storyboard = UIStoryboard.FromName ("Main", null);
var webController = storyboard.InstantiateViewController ("ViewController") as ViewController;
this.NavigationController.PushViewController (webController, false);
if (Reachability.IsHostReachable ("http://google.com")) {
if (BizApplication.CheckCredential ()) {
//window = new UIWindow (UIScreen.MainScreen.Bounds);
Menu = new SlideoutNavigationController ();
storyboard = UIStoryboard.FromName ("Main", null);
var webController = storyboard.InstantiateViewController ("SearchViewController") as SearchViewController;
NavigationController.PushViewController (webController, false);
Menu.MainViewController = new MainNavigationController (webController, Menu);
Menu.MenuViewController = new MenuNavigationController (new DummyControllerLeft (), Menu) { NavigationBarHidden = true };
this.NavigationController.PushViewController (Menu);
//window.RootViewController = Menu;
//window.MakeKeyAndVisible ();
}
}
注销时..调用以下命令:
void onLogOut (object sender, EventArgs e)
{
//Write your code to clear
var vwControllers = this.NavigationController.ViewControllers;
foreach(UIViewController signinVC in vwControllers) {
if (signinVC.GetType () == typeof (ViewController)) {
this.NavigationController.PopToViewController (ViewController);
}
}
}
我认为你们应该以模态的方式展示你们的视图控制器,因为你们不需要后退按钮,所以并没有必要在堆栈中推它们 而不是
navigationcontroller.pushviewcontroller()
使用
您可以在注销时使用
dismissviewcntroller()
,这不会更改登录屏幕中的导航栏登录完成后如何推送新屏幕?你能分享我的代码吗?@NinjaHattori查看我的更新代码。@NinjaHattori如果你需要其他代码,请告诉我我会更新它。等一下,我尝试了解决方案,很快就会回来。我有liitle问题,因为我在故事板中使用了SpalshViewController
。你能解释一下你有什么问题吗?查看我的更新问题。正如您所说,我已经调用了我的DummyControllerLeft.cs
文件。您还没有指定您现在面临的问题是什么?