P
P
Paul Fawkes2019-09-16 21:24:58
React
Paul Fawkes, 2019-09-16 21:24:58

Why don't xamarin buttons work?

I am doing a project following the example https://docs.microsoft.com/en-us/xamarin/ios/get-s... I click on the call or translate buttons and the application freezes stupidly

public partial class ViewController : UIViewController
{
    public ViewController(IntPtr handle) : base(handle)
    {
    }

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

        string translatedNumber = "";

        TranslateButton.TouchUpInside += (object sender, EventArgs e) => {
            translatedNumber = PhoneTranslator.ToNumber(
                PhoneNumberText.Text);

            PhoneNumberText.ResignFirstResponder();

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

        CallButton.TouchUpInside += (object sender, EventArgs e) => {
            var url = new NSUrl("tel:" + translatedNumber);

            if (!UIApplication.SharedApplication.OpenUrl(url))
            {
                var alert = UIAlertController.Create("Not supported", "Scheme 'tel:' is not supported on this device", UIAlertControllerStyle.Alert);
                alert.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Default, null));
                PresentViewController(alert, true, null);
            }
        };

    }

    public override void DidReceiveMemoryWarning()
    {
        base.DidReceiveMemoryWarning();
    }

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
Roman Aleksandrovich, 2018-04-18
@RomReed

@melkaya94, <code lang="javascript">
async handleOnClick(i){
    await this.setState({
      selectCard: {
        ...this.state.selectCard,
        [i]: !this.state.selectCard[i]
      }
    },() => {this.amountSelectSwatches(this.state.selectCard,i)}); // вызов счетчика

  }
  amountSelectSwatches(obj,ind){ 
if(obj[ind]===true){
 await this.setState({
count:Object.assign({},this.state.count,{[ind]:++this.state.count[ind]})
})
}}
</code>

если вам это не нравится вы можете использовать глобальную переменную для хранения count

D
davidnum95, 2018-04-18
@davidnum95

You have chosen a strange way of storing selected cards. Why do you need an object? Store just an array.
Example

V
Vyacheslav Zolotov, 2019-09-16
@SZolotov

I did everything as in the guide, it works for me.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question