I'm getting a black window after navigating to a view controller. My app is calling a page from app delegate from the OpenUrl method.
public override bool OpenUrl(UIApplication app, NSUrl url, string sourceApp, NSObject annotation)
{
var rurl = new Rivets.AppLinkUrl(url.ToString());
// navController = new UINavigationController();
var id = string.Empty;
if (rurl.InputQueryParameters.ContainsKey("id"))
id = rurl.InputQueryParameters["id"];
if (rurl.InputUrl.Host.Equals("products") && !string.IsNullOrEmpty(id))
{
// var mainController = new UIViewController();
// NSUserDefaults.StandardUserDefaults.SetBool(true, "ForgotPwdLinkClicked");
return true;
}
else
{
//var c = new ProductViewController();
// UIApplication.SharedApplication.KeyWindow.RootViewController = c;
var c = new UpdatePasswordViewController();
navigationController.ModalPresentationStyle = UIModalPresentationStyle.OverFullScreen;
navigationController.PushViewController
(c, true);
//// return true ;
///*this.Window.RootViewController =
// c;*/
// NSUserDefaults.StandardUserDefaults.SetBool(true, "ForgotPwdLinkClicked");
return true;
}
}
These are my ViewController settings in XCode:
This Code resolve my issue
UIStoryboard Storyboard = UIStoryboard.FromName("MainStoryboard", null);// this will bee our storyboard name
var c = Storyboard.InstantiateViewController("UpdatePasswordViewController") as UpdatePasswordViewController;
Related
I have custom annotation which I have subClass from MKPointAnnotation. Adding those is working properly. I also need to detect the Annotation select method. The problem is when I tap on the annotation it doesn't hit the "DidSelectAnnotationView" at first. if I tap into another annotation like userLocation annotation then "DidSelectAnnotationView" hits. and while debugging it shows the coordinates of the annotation view is not the user location but the annotation I tap previously. and same happens after this when I tap my custom annotation it hits the method and coordinates of the method is not the userLocation one. I have added my code, could someone look into it where I missed the bits.
override public MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation)
{
string resuseId = "customAnnotation";
MKAnnotationView annotationView = mapView.DequeueReusableAnnotation(resuseId);
if (ThisIsTheCurrentLocation(mapView, annotation))
{
return null;
}
if (annotationView == null)
{
if (annotation is CustomAnnotation)
{
switch (CustomAnnotation.MarkerType)
{
case MyMarkerType.Note:
annotationView = new MKAnnotationView(annotation, resuseId);
annotationView.Image = UIImage.FromBundle("Message");
annotationView.CanShowCallout = false;
annotationView.Enabled = true;
break;
case MyMarkerType.Photo:
annotationView = new MKAnnotationView(annotation, resuseId);
annotationView.Image = UIImage.FromBundle("Photo");
annotationView.CanShowCallout = false;
break;
case MyMarkerType.Story:
annotationView = new MKAnnotationView(annotation, resuseId);
var Img = UIImage.FromBundle("Story");
annotationView.CanShowCallout = false;
break;
case MyMarkerType.Custom:
annotationView = new MKAnnotationView(annotation, resuseId);
//using (var data = NSData.FromArray(CustomAnnotation.WayPoint.Image))
//{
// var image = UIImage.LoadFromData(data);
// annotationView.Image = image;
//}
NSData data = NSData.FromArray(CustomAnnotation.WayPoint.Image);
UIImage image = UIImage.LoadFromData(data);
// UIImage finalImage = image.MaxResizeImage(21f, 20f);
annotationView.Image = image;
annotationView.CanShowCallout = false;
break;
default:
annotationView = new MKAnnotationView(annotation, resuseId);
//var imaget = FromUrl(CustomAnnotation.WayPoint.IconUrl);
//annotationView.Image = imaget;
break;
}
}
else{
annotationView.Annotation = annotation;
annotationView.CanShowCallout = false;
//(annotationView as MKPinAnnotationView).AnimatesDrop = false; // Set to true if you want to animate the pin dropping
//(annotationView as MKPinAnnotationView).PinTintColor = UIColor.Red;
annotationView.SetSelected(false, false);
}
}
return annotationView;
}
And my DidSelect Method
public override void DidDeselectAnnotationView(MKMapView mapView, MKAnnotationView view)
{
if ( view.Annotation.Coordinate.Latitude == mapView.UserLocation.Coordinate.Latitude){
return;
}
CLLocationCoordinate2D coordinates = view.Annotation.Coordinate;
mapView.DeselectAnnotation(view.Annotation, false);
// GetAnnotationClickInfo.Invoke(coordinates);
}
Use DidSelectAnnotationView method,
not DidDeselectAnnotationView.
public override void DidSelectAnnotationView(MKMapView mapView, MKAnnotationView view)
DidDeselectAnnotationView
DidSelectAnnotationView
After checking your code , I think there is a mistaken when initializing that annotationView ,you should put annotationView.Annotation = annotation; outside the condition if (annotationView == null).
Mofidy your code :
if (annotationView == null)
{
if (annotation is CustomAnnotation)
{
//custom view logic
}
else //not custom view
{
annotationView = new MKPinAnnotationView(annotation, annotationIdentifier);
}
}
else
{
annotationView.Annotation = annotation;
}
annotationView.CanShowCallout = false;
//(annotationView as MKPinAnnotationView).AnimatesDrop = false; // Set to true if you want to animate the pin dropping
//(annotationView as MKPinAnnotationView).PinTintColor = UIColor.Red;
annotationView.SetSelected(false, false);
I'm migrating one of my Asp.Net MVC 5 project to Asp.Net Core. I have a custom ActionResult, which renders the view as partial view if the request was ajax request, and renders the view as normal view with layout if the request was a normal request. I have issues with converting the old ExecuteResult to new ExecuteResultAsync.
Here it is my old code:
public override void ExecuteResult(ControllerContext context)
{
context.HttpContext.Response.Buffer = true;
context.Controller.ViewData.Model = Model;
using (var sw = new StringWriter())
{
var request = context.RequestContext.HttpContext.Request;
if (string.IsNullOrEmpty(ViewName))
{
ViewName = request.RequestContext.RouteData.GetRequiredString("action");
}
var viewResult = request.IsAjaxRequest()
? ViewEngines.Engines.FindPartialView(context, ViewName)
: ViewEngines.Engines.FindView(context, ViewName, "_Layout");
var viewContext = new ViewContext(context, viewResult.View, context.Controller.ViewData, context.Controller.TempData, sw);
viewResult.View.Render(viewContext, sw);
context.HttpContext.Response.Write(sw.GetStringBuilder().ToString());
}
}
And here it is my half converted code:
public override async Task ExecuteResultAsync(ActionContext context)
{
context.HttpContext.Response.Buffer = true; //broken
context.HttpContext.Controller.ViewData.Model = Model; //broken
using (var sw = new StringWriter())
{
var request = context.HttpContext.Request;
if (string.IsNullOrEmpty(ViewName))
ViewName = context.ActionDescriptor.Name;
var engine = context.HttpContext.RequestServices.GetService(typeof(ICompositeViewEngine)) as ICompositeViewEngine;
var viewResult = request.Headers["X-Requested-With"] == "XMLHttpRequest"
? engine.FindPartialView(context, ViewName)
: engine.FindView(context, ViewName);
var viewContext = new ViewContext(context, viewResult.View, context.Controller.ViewData, context.Controller.TempData, sw, new HtmlHelperOptions()); //broken
await viewResult.View.RenderAsync(viewContext);
await context.HttpContext.Response.WriteAsync(sw.GetStringBuilder().ToString());
}
}
My main issue is the ControllerContext -> ActionContext migrating. Please help me to convert ControllerContext to ActionContext. Thank you very much!
Ehh, put something together to fit RC2 bits real quick. Feel free to improve on it:
public override async Task ExecuteResultAsync(ActionContext context)
{
var request = context.HttpContext.Request;
if (string.IsNullOrEmpty(ViewName))
{
ViewName = context.ActionDescriptor.Name;
}
var engine = context.HttpContext.RequestServices.GetService(typeof(ICompositeViewEngine)) as ICompositeViewEngine;
var viewResult = engine.FindView(context, ViewName, isMainPage: request.Headers["X-Requested-With"] != "XMLHttpRequest");
var tempDataProvider = context.HttpContext.RequestServices.GetService(typeof(ITempDataProvider)) as ITempDataProvider;
var modelMetaDataProvider = context.HttpContext.RequestServices.GetService(typeof(IModelMetadataProvider)) as IModelMetadataProvider;
using (var writer = new HttpResponseStreamWriter(context.HttpContext.Response.Body, Encoding.UTF8))
{
var tempData = new TempDataDictionary(context.HttpContext, tempDataProvider);
var viewData = new ViewDataDictionary(modelMetaDataProvider, context.ModelState)
{
Model = Model
};
var viewContext = new ViewContext(
context,
viewResult.View,
viewData,
tempData,
writer,
new HtmlHelperOptions());
await viewResult.View.RenderAsync(viewContext);
}
}
In my application, I'm using the MvxTabBarViewController to display some tabs (the MvxTabBarViewController is loaded using a Storyboard):
public partial class RootView : MvxTabBarViewController
{
private int _tabIndex = 0;
private Dictionary<int, SectionBase> _sectionBaseForConfig;
public new RootViewModel ViewModel
{
get { return (RootViewModel)base.ViewModel; }
set { base.ViewModel = value; }
}
public RootView(IntPtr handle)
: base(handle)
{
}
UIViewController tab1, tab2, tab3, tab4, tab5, tab6, tab7;
public override async void ViewDidLoad()
{
base.ViewDidLoad();
if (ViewModel == null)
return;
tab1 = new UIViewController();
tab1.Title = "1";
tab1.View.BackgroundColor = UIColor.Green;
tab2 = new UIViewController();
tab2.Title = "2";
tab2.View.BackgroundColor = UIColor.Orange;
tab3 = new UIViewController();
tab3.Title = "3";
tab3.View.BackgroundColor = UIColor.Red;
tab4 = new UIViewController();
tab4.Title = "4";
tab4.View.BackgroundColor = UIColor.Blue;
tab5 = new UIViewController();
tab5.Title = "5";
tab5.View.BackgroundColor = UIColor.Brown;
tab6 = new UIViewController();
tab6.Title = "6";
tab6.View.BackgroundColor = UIColor.Brown;
tab7 = new UIViewController();
tab7.Title = "7";
tab7.View.BackgroundColor = UIColor.Brown;
var tabs = new UIViewController[] {
tab1, tab2, tab3, tab4, tab5, tab6, tab7
};
ViewControllers = tabs;
CustomizableViewControllers = null;
SelectedViewController = ViewControllers[0];
}
}
Unfortunately, even if there are 7 tabs, only 5 are displayed and the "More" button does not show. Anyone got an idea ? I stuck on this problem since 2 hrs now, without any clues :(
Thanks!
I'm building an iOS view using Xamarin and MvvmCross and I have come across an interesting little issue. I can't seem to add more than one UIPickerView to a UIView.
Add one view and all works well. Add a second and the simulator just hangs when I try and open the page.
This seems to be related to a UITextField with an InputView as I also have an issue if I try to add a UIDatePicker as well.
Nothing strange in the debug output.
Here is the code:
[Register("EditJobViewJobView")]
public class EditJobView : MvxViewController
{
public new EditJobViewModel ViewModel
{
get { return (EditJobViewModel)base.ViewModel; }
}
private const float _leftMargin = 6;
private const float _labelHeight = 20;
private const float _pickerHeight = 28;
private readonly UIFont _labelFont = UIFont.BoldSystemFontOfSize(18f);
private readonly UIFont _controlFont = UIFont.SystemFontOfSize(18f);
private readonly UIView _paddingInsert = new UIView(new RectangleF(0, 0, 4, 0));
private int _currentTop = 0;
public override void ViewDidLoad()
{
base.ViewDidLoad();
View = new UIView() { BackgroundColor = UIColor.White };
NavigationItem.SetRightBarButtonItem(new UIBarButtonItem("Save", UIBarButtonItemStyle.Bordered,
(sender, args) => ViewModel.OkCommand.Execute(null)), true);
// ios7 layout
if (RespondsToSelector(new Selector("edgesForExtendedLayout")))
EdgesForExtendedLayout = UIRectEdge.None;
Title = "Edit Job";
AddLabel("Job Status");
MvxPickerViewModel jobStatusPickerViewModel;
var jobStatusTextView = AddPickerView(out jobStatusPickerViewModel);
AddLabel("Job Priority");
MvxPickerViewModel jobPriorityPickerViewModel;
var jobPriorityTextView = AddPickerView(out jobPriorityPickerViewModel);
var set = this.CreateBindingSet<EditJobView, EditJobViewModel>();
set.Bind(jobStatusPickerViewModel).For(p => p.SelectedItem).To(vm => vm.SelectedJobStatusType);
set.Bind(jobStatusPickerViewModel).For(p => p.ItemsSource).To(vm => vm.JobStatusTypes);
set.Bind(jobStatusTextView).To(vm => vm.SelectedJobStatusType);
set.Bind(jobPriorityPickerViewModel).For(p => p.SelectedItem).To(vm => vm.SelectedJobPriority);
set.Bind(jobPriorityPickerViewModel).For(p => p.ItemsSource).To(vm => vm.JobPriorities);
set.Bind(jobPriorityTextView).To(vm => vm.SelectedJobPriority);
set.Apply();
}
private void AddLabel(string caption)
{
_currentTop += 10;
var frame = new RectangleF(_leftMargin, _currentTop, 300, _labelHeight);
var label = new UILabel(frame);
label.Font = _labelFont;
label.Text = caption;
AddView(label);
_currentTop += 2;
}
private UITextField AddPickerView(out MvxPickerViewModel pickerViewModel)
{
var textField = AddTextField();
var pickerView = new UIPickerView();
pickerViewModel = new MvxPickerViewModel(pickerView);
pickerView.Model = pickerViewModel;
pickerView.ShowSelectionIndicator = true;
textField.InputView = pickerView;
return textField;
}
private UITextField AddTextField()
{
var frame = new RectangleF(_leftMargin, _currentTop, 300, _pickerHeight);
var textField = new UITextField(frame);
textField.Layer.BorderColor = UIColor.Black.CGColor;
textField.Layer.BorderWidth = 1f;
textField.Font = _controlFont;
textField.LeftView = _paddingInsert;
textField.LeftViewMode = UITextFieldViewMode.Always;
AddView(textField);
return textField;
}
private void AddView(UIView view)
{
View.AddSubview(view);
_currentTop += (int)view.Frame.Height;
}
}
Any ideas?
This was caused by creating a shared padding insert across a number of UITextFields.
To fix this I changed
textField.LeftView = _paddingInsert;
to
textField.LeftView = new UIView(new RectangleF(0, 0, 4, 0));
I have a monotouch dialog view controller. I have a number of nested root elements
public RootElement LoginSection()
{
//var rootSection = new Section("");
var root = new RootElement ("I'm already a member");
EntryElement emailEnt = new EntryElement ("Login","Username or Email","");
EntryElement passwdEnt = new EntryElement ("Password","Password","",true);
StyledStringElement loginBtn = new StyledStringElement ("Login"){
Accessory = UITableViewCellAccessory.DetailDisclosureButton
};
Section loginDetails = new Section("Your Details"){emailEnt,passwdEnt,loginBtn};
loginBtn.Tapped += () => {
var result = ApiOperations.ApiValidateLoginCredentials (emailEnt.Value, passwdEnt.Value);
if (result) {
var login = DataOperations.DbGetLogin ();
//first time user so we need to save their details into the db
if (login == null) {
} else {
BTProgressHUD.Show ("Logging In", -1, BTProgressHUD.MaskType.Black);
BTProgressHUD.InvokeInBackground (delegate {
ApiOperations.QrCode (login.ConsumerId);
ApiOperations.ApiConsumer (login.ConsumerId);
AuthenicatedActionCompleted.Invoke (this, new EventArgs ());
BTProgressHUD.Dismiss ();
});
}
} else {
//didnt work
using (var alert = new UIAlertView ("Unable to login", "Please try again.", null, "OK", null))
alert.Show ();
}
};
root.Add (loginDetails);
return root;
}
My problem is the the length of each of the element titles. My top level root title is also long e.g. Welcome to my application
If I tap on an rootelement above the back button shows "welcome to...." ideally I would like the button to show "back" vs the long string.
Is it possible to update this?
Ok solved it. If anyone else has the same problem this worked for me.
The last line is the trick.
public override void LoadView ()
{
base.LoadView ();
View.BackgroundColor =UIColor.Clear;
TableView.BackgroundView = null;
var background = UIImage.FromBundle(Resources.BackgroundImagePath);
ParentViewController.View.BackgroundColor = UIColor.FromPatternImage (background);
this.NavigationItem.BackBarButtonItem = new UIBarButtonItem ("Back", UIBarButtonItemStyle.Plain, null);
}