Problem with intro iOS Xamarin tutorial

ernmaernma SEMember

On step 21 in https://developer.xamarin.com/guides/ios/getting_started/hello,_iOS/hello,iOS_quickstart/ when pasting the provided code into ViewController.cs, Visual Studio for mac says: The name 'PhoneTranslator' does not exist in the current context, about the line containing translatedNumber = PhoneTranslator.ToNumber(PhoneNumberText.Text);. I'm pasting the entire file with the code included:

using System;
using Foundation;

using UIKit;

namespace phoneword_iOS
{
public partial class ViewController : UIViewController
{
protected ViewController(IntPtr handle) : base(handle)
{
// Note: this .ctor should not contain any initialization logic.
}

    public override void ViewDidLoad()
    {
        base.ViewDidLoad();
        // Perform any additional setup after loading the view, typically from a nib.


        string translatedNumber = "";

        TranslateButton.TouchUpInside += (object sender, EventArgs e) =>
        {
            // Convert the phone number with text to a number
            // using PhoneTranslator.cs
            translatedNumber = PhoneTranslator.ToNumber(
                PhoneNumberText.Text);

            // Dismiss the keyboard if text field was tapped
            PhoneNumberText.ResignFirstResponder();

            if (translatedNumber == "")
            {
                CallButton.SetTitle("Call ", UIControlState.Normal);
                CallButton.Enabled = false;
            }
            else
            {
                CallButton.SetTitle("Call " + translatedNumber,
                    UIControlState.Normal);
                CallButton.Enabled = true;
            }
        };

    }

    public override void DidReceiveMemoryWarning()
    {
        base.DidReceiveMemoryWarning();
        // Release any cached data, images, etc that aren't in use.
    }
}

}

Posts

  • ernmaernma SEMember
    edited January 2017

    In the visual studio version of the tutorial there is a problem with the line

    TranslateButton.TouchUpInside += (object sender, EventArgs e) =>

    and this

    translatedNumber = PhonewordTranslator.ToNumber(PhoneNumberText.Text);

    works better if...

    translatedNumber = Phoneword_iOS.PhoneTranslator.ToNumber(

  • I downloaded Visual Studio 2017 Community Edition both for Windows and for the Mac yesterday. The sample at this URL:

    https://developer.xamarin.com/guides/ios/getting_started/hello,_iOS/hello,iOS_quickstart/

    still fails the same way. There were previous suggestions to "force restart" the computer (Not exactly sure what that means since when you select "restart" from the power button, Windows 10 just closes the solution/project when it shuts down. I believe that simply closing the solution and reopening it accomplishes the same thing. It seemed to work for me. I continued on and when I reached Step 23, which said to "Edit the application name and icons in the Project Properties To do this right-click on the Project in the Solution Explorer and select properties. Go to the iOS Application Tab.", the screen shot in the sample/tutorial shows this iOS Application tab, but my version does not show it. I could not perform those steps as a result.

    I built the solution and launched it anyway, and it seems to work as expected on the simulator on the Mac. What am I missing by not performing those steps?

  • I was wrong. Closing and reopening the solution does not fix the error. It went away only after I rebooted. :(

    I'm perfectly set up to use Xamarin and C# for iOS app dev, but I'm reluctant to base a development effort on it when an error mentioned in January is still present in August. Since a reboot fixes it, it's hard to believe that this could be a user error.

  • NashZhouNashZhou USMember ✭✭✭
    edited August 2017

    @DennisSchaefer Xamarin's tutorials aren't always the most up to date (for example, pictures still use Xamarin Studio as the IDE) but I looked at this sample, followed the tutorial, and I'm not running into any errors. I don't have to reboot or reopen my solution.

    ernma ran into a user error. You can see ernma used 2 different names for namespaces (One is "phoneword_iOS" and the other is "Phoneword_iOS" so ernma has an inconsistency in capitalizing the "P").

    It would be great if you could elaborate on your error rather than giving a solution that there 'were previous suggestions to "force restart" the computer' when it doesn't say you have to in the tutorial.

    I can't comment on step 24 as I don't run a Windows machine, though hopefully it isn't too hard to find the iOS properties.

  • ernmaernma SEMember

    @NashZhou Thanks for pointing out my error, I see it now.

    @DennisSchaefer Sorry to see you ran into the issue you mentioned. I went back to java development for a while!

  • @NashZhou

    Thanks for your comments.

    Yes, I'm doing the tutorial in VS 2017 Community on a Windows 10 machine attached to a Mac.

    VS 2017 was downloaded on both machines and installed on 8/15/17, so I'm making an assumption that the versions were the same. All of the connections to the Mac work fine.

    When I do the tutorial, when adding the code at Step 20, the following line shows the error "PhoneTranslator does not exist in this context":

    translatedNumber = PhoneTranslator.ToNumber(PhoneNumberText.Text);

    The namespace used in all code is Phoneword. I'm certain it is the same everywhere.

    When the error occurs. I save all code, close VS, and reboot Windows. When I reopen the project after reboot, the error is gone. That indicates it was not a user error.

    The tutorial/sample doesn't indicate that it's for Windows only, so why wouldn't all steps be valid for VS on the Mac as well? In any case, the tab containing the items to be modified, iOS Application, does not show up when I follow the instructions at Step 23 (not 24). I haven't found anything like these pages yet.

  • JGoldbergerJGoldberger USMember, Forum Administrator, Xamarin Team, University Xamurai
    edited August 2017

    There is a switch in the upper right of many of the Xamarin documents pages to switch from VS (Windows) to VS (Mac):

    If you compare the two pages side by side, you will see several differences and the step numbers do not line up and by the time you get to step 23, actually well before then, they are off.

Sign In or Register to comment.