如何设置隐藏在Xamarin中的UIView

时间:2015-06-30 01:57:09

标签: c# ios xamarin xamarin.ios

我正在使用Xamarin构建我的第一个应用程序。我创建了一个名为reord_overlay的UIView。我想在ViewDidLoad之后将其设置为隐藏:

record_overlay.Hidden = true;

我得到的是关于

的错误
../VoYo/iOS/ViewController.designer.cs(27,27): Error CS0102: The type `VoYo.iOS.ViewController' already contains a definition for `recording' (CS0102) (VoYo.iOS)

如何将视图设置为隐藏?

错误说它在我的ViewController.designer.cs文件中:

// WARNING
//
// This file has been generated automatically by Xamarin Studio from the outlets and
// actions declared in your storyboard file.
// Manual changes to this file will not be maintained.
//
using Foundation;
using System;
using System.CodeDom.Compiler;
using UIKit;

namespace VoYo.iOS
{
    [Register ("ViewController")]
    partial class ViewController
    {
        [Outlet]
        UIKit.UIButton Button { get; set; }

        [Outlet]
        [GeneratedCode ("iOS Designer", "1.0")]
        UIView record_overlay { get; set; }

        [Outlet]
        [GeneratedCode ("iOS Designer", "1.0")]
        UIActivityIndicatorView recording { get; set; }

        [Outlet]
        [GeneratedCode ("iOS Designer", "1.0")]
        UIActivityIndicatorView recording { get; set; }

        [Outlet]
        [GeneratedCode ("iOS Designer", "1.0")]
        UITextView Voice { get; set; }

        void ReleaseDesignerOutlets ()
        {
            if (record_overlay != null) {
                record_overlay.Dispose ();
                record_overlay = null;
            }
            if (recording != null) {
                recording.Dispose ();
                recording = null;
            }
            if (recording != null) {
                recording.Dispose ();
                recording = null;
            }
            if (Voice != null) {
                Voice.Dispose ();
                Voice = null;
            }
        }
    }
}

我的代码

using System;

using UIKit;

namespace VoYo.iOS
{
    public partial class ViewController : UIViewController
    {
        //int count = 1;

        public ViewController (IntPtr handle) : base (handle)
        {       
        }


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

            // Code to start the Xamarin Test Cloud Agent
            #if ENABLE_TEST_CLOUD
            Xamarin.Calabash.Start ();
            #endif

            // Perform any additional setup after loading the view, typically from a nib.
            Button.AccessibilityIdentifier = "myButton";
            string[] countries = {"Afghanistan", "Albania", "Algeria", "American Samoa", "Andorra", "Angola", "Anguilla", "Antarctica", "Antigua and Barbuda", "Argentina", "Armenia", "Aruba", "Australia", "Austria", "Azerbaijan", "Bahamas", "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium", "Belize", "Benin", "Bermuda", "Bhutan", "Bolivia", "Bosnia and Herzegowina", "Botswana", "Bouvet Island", "Brazil", "British Indian Ocean Territory", "Brunei Darussalam", "Bulgaria", "Burkina Faso", "Burundi", "Cambodia", "Cameroon", "Canada", "Cape Verde", "Cayman Islands", "Central African Republic", "Chad", "Chile", "China", "Christmas Island", "Cocos (Keeling) Islands", "Colombia", "Comoros", "Congo", "Congo, the Democratic Republic of the", "Cook Islands", "Costa Rica", "Cote d'Ivoire", "Croatia (Hrvatska)", "Cuba", "Cyprus", "Czech Republic", "Denmark", "Djibouti", "Dominica", "Dominican Republic", "East Timor", "Ecuador", "Egypt", "El Salvador", "Equatorial Guinea", "Eritrea", "Estonia", "Ethiopia", "Falkland Islands (Malvinas)", "Faroe Islands", "Fiji", "Finland", "France", "France Metropolitan", "French Guiana", "French Polynesia", "French Southern Territories", "Gabon", "Gambia", "Georgia", "Germany", "Ghana", "Gibraltar", "Greece", "Greenland", "Grenada", "Guadeloupe", "Guam", "Guatemala", "Guinea", "Guinea-Bissau", "Guyana", "Haiti", "Heard and Mc Donald Islands", "Holy See (Vatican City State)", "Honduras", "Hong Kong", "Hungary", "Iceland", "India", "Indonesia", "Iran (Islamic Republic of)", "Iraq", "Ireland", "Israel", "Italy", "Jamaica", "Japan", "Jordan", "Kazakhstan", "Kenya", "Kiribati", "Korea, Democratic People's Republic of", "Korea, Republic of", "Kuwait", "Kyrgyzstan", "Lao, People's Democratic Republic", "Latvia", "Lebanon", "Lesotho", "Liberia", "Libyan Arab Jamahiriya", "Liechtenstein", "Lithuania", "Luxembourg", "Macau", "Macedonia, The Former Yugoslav Republic of", "Madagascar", "Malawi", "Malaysia", "Maldives", "Mali", "Malta", "Marshall Islands", "Martinique", "Mauritania", "Mauritius", "Mayotte", "Mexico", "Micronesia, Federated States of", "Moldova, Republic of", "Monaco", "Mongolia", "Montserrat", "Morocco", "Mozambique", "Myanmar", "Namibia", "Nauru", "Nepal", "Netherlands", "Netherlands Antilles", "New Caledonia", "New Zealand", "Nicaragua", "Niger", "Nigeria", "Niue", "Norfolk Island", "Northern Mariana Islands", "Norway", "Oman", "Pakistan", "Palau", "Panama", "Papua New Guinea", "Paraguay", "Peru", "Philippines", "Pitcairn", "Poland", "Portugal", "Puerto Rico", "Qatar", "Reunion", "Romania", "Russian Federation", "Rwanda", "Saint Kitts and Nevis", "Saint Lucia", "Saint Vincent and the Grenadines", "Samoa", "San Marino", "Sao Tome and Principe", "Saudi Arabia", "Senegal", "Seychelles", "Sierra Leone", "Singapore", "Slovakia (Slovak Republic)", "Slovenia", "Solomon Islands", "Somalia", "South Africa", "South Georgia and the South Sandwich Islands", "Spain", "Sri Lanka", "St. Helena", "St. Pierre and Miquelon", "Sudan", "Suriname", "Svalbard and Jan Mayen Islands", "Swaziland", "Sweden", "Switzerland", "Syrian Arab Republic", "Taiwan, Province of China", "Tajikistan", "Tanzania, United Republic of", "Thailand", "Togo", "Tokelau", "Tonga", "Trinidad and Tobago", "Tunisia", "Turkey", "Turkmenistan", "Turks and Caicos Islands", "Tuvalu", "Uganda", "Ukraine", "United Arab Emirates", "United Kingdom", "United States", "United States Minor Outlying Islands", "Uruguay", "Uzbekistan", "Vanuatu", "Venezuela", "Vietnam", "Virgin Islands (British)", "Virgin Islands (U.S.)", "Wallis and Futuna Islands", "Western Sahara", "Yemen", "Yugoslavia", "Zambia", "Zimbabwe"};
            record_overlay.Hidden = true;
            Button.TouchUpInside += delegate {
                //var title = string.Format ("{0} clicks!", count++);
                //Button.SetTitle (title, UIControlState.Normal);
                Random rnd = new Random();
                int length = countries.Length;
                int i = rnd.Next(0, length);
                Voice.Text = "You sound like someone from "+countries[i];
            };
        }

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

2 个答案:

答案 0 :(得分:0)

删除2个声明的UIActivityIndicatorView recording { get; set; }中的一个 在ViewController.designer.cs

请务必仔细检查任何出口参考剩余物以记录UIActivityIndi​​catorView

答案 1 :(得分:0)

record_overlay.Hidden = true; bug无关。

只需使用Xcode Interface Builder打开您的XIB,删除UIActivityIndicatorView recording的出口参考,打开ViewController.h并删除属性,如下所示:

@property (nonatomic, retain) IBOutlet UIActivityIndicatorView *recording;

您可能有2个重复的行,只需删除并再次添加插座即可。