iPhone App2011. 6. 23. 15:02

반 구조체 같은 경우 컬렉션에 넣을수 없다.

예를 들면 NSRect같은것은 바로 array에 addObject로 넣으면 안들어가기때문에 NSValue로 한번 감싸서 넣어준다.

물론 숫자 int,float등도 바로 넣을수 없기떄문에 NSNumber로 한번 감싸서 넣어준다.

NSMutableArray *mutableArray= [NSMutableArray arrayWithCapacity:2];

NSRect rect = NSMakeRect (1, 2, 30, 40);

NSValue *value;

value = [NSValue valueWithBytes:&rect objCType: @encode(NSRect)];

[mutableArray addObject: value];

NSValue *value2; NSRect rect2;

value2 = [mutableArray objectAtIndex: 0];

[value2 getValue: &rect2];

NSLog(@"Data %f %f",rect2.size.width,rect2.size.height); 

Posted by 동동(이재동)
Windows Phone 72011. 1. 6. 21:48

예전 포스트에서도 썻지만 약간 달라져서 다시 쓴다.

 

먼저 이런식으로 notifyPropertyChanged 이벤트 클래스를 하나만든다.

 

public class ItemCoinInfo : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;
 
        public ItemCoinInfo()
        {
 
        }
    
        #region TypeProperty
        private ItemCoinType _type;
        /// <summary>
        /// 
        /// </summary>
        public ItemCoinType Type
        {
            get
            {
                return _type;
            }
            set
            {                
                if (value != _type)
                {
                    _type = value;
                    if (PropertyChanged != null)
                    {
                        PropertyChanged(this, new PropertyChangedEventArgs("Type"));
                    }
                }
            }
        }
        #endregion TypeProperty            
    
        
        #region CountProperty
        private int _count;
        /// <summary>
        /// 
        /// </summary>
        public int Count
        {
            get
            {
                return _count;
            }
            set
            {
                if (value != _count)
                {
                    _count = value;
                    if (PropertyChanged != null)
                    {
                        PropertyChanged(this, new PropertyChangedEventArgs("Count"));
                        PropertyChanged(this, new PropertyChangedEventArgs("DisplayName"));
                    }
                }
            }
        }
 
        private string _name;
        public string Name
        {
            get
            {
                return _name;
            }
            set
            {
                if (value != _name)
                {
                    _name = value;
                    if (PropertyChanged != null)
                    {
                        PropertyChanged(this, new PropertyChangedEventArgs("Name"));
                    }
                }
            }
        }
 
        private string _displayName;
        public string DisplayName
        {
            get
            {
                _displayName = string.Format("{0} X {1}", Name, Count);
                return _displayName;
            }           
        }
 
        #endregion MyPropertyProperty                
    }
 
그뒤에는
이것을  다시
public static class ItemList
  {
      public static ObservableCollection<ItemCoinInfo> ItemsInfo { get; set; }
 
      static ItemList()
      {
          ItemsInfo = new ObservableCollection<ItemCoinInfo>();
 
          if (ItemsInfo.Count == 0)
          {
              //todo : 현재는 강제로 넣고 있지만 나중에는 xml에서 읽어올것 without count
              //초기에만 넣는다는 것을 잊으면 안됨 나중에 확장을 생각할것 -jdlee
              ItemsInfo.Add(new ItemCoinInfo { Count = 0, Type = ItemCoinType.FC1, Name = "Fortune Coin" });
              ItemsInfo.Add(new ItemCoinInfo { Count = 0, Type = ItemCoinType.PC1, Name = "Pray Coin" });
              ItemsInfo.Add(new ItemCoinInfo { Count = 0, Type = ItemCoinType.WC1, Name = "Web Coin" });
          }
      }
  }

 

이렇게 만들고

여기 안의 count개수를 이런식으로 linq로 늘리면?

//아이템 개수를 하나 늘린다.          
               var type = (ItemCoinType)Enum.Parse(typeof(ItemCoinType), viewmodel.CoinInfo.Id, true);
               (from p in ItemList.ItemsInfo where p.Type == type select p).FirstOrDefault().Count += 1;              

 

자동으로 이것을 바인딩한 컨트롤은 바뀐다.

Posted by 동동(이재동)