Inheritance: IDisposable
Exemplo n.º 1
0
 public new static NSMutableDictionary FromObjectAndKey(NSObject obj, string key)
 {
     IntPtr handle = ObjC.ToNSString(key);
     var dictionary = Runtime.GetNSObject<NSMutableDictionary>(ObjC.MessageSendIntPtr(_classHandle, Selector.GetHandle("dictionaryWithObject:forKey:"), obj.Handle, handle));
     ObjC.MessageSend(handle, Selector.ReleaseHandle);
     return dictionary;
 }
Exemplo n.º 2
0
 public NSObject AddObserver(string name, Action<NSNotification> action, NSObject fromObject = null)
 {
     var handler = new Observer(action);
     Callbacks.Subscribe(handler, SelectorName, n => action(Runtime.GetNSObject<NSNotification>(n)));
     ObjC.MessageSend(Handle, Selector.GetHandle("addObserver:selector:name:object:"), handler.Handle, Selector.GetHandle(SelectorName), name, fromObject == null ? IntPtr.Zero : fromObject.Handle);
     return handler;
 }
Exemplo n.º 3
0
 public new static NSMutableDictionary FromObjectsAndKeys(NSObject[] objects, string[] keys)
 {
     var objectsHandle = ObjC.ToNSArray(objects);
     var keysHandle = ObjC.ToNSArray(keys);
     var dictionary = Runtime.GetNSObject<NSMutableDictionary>(ObjC.MessageSendIntPtr(_classHandle, Selector.GetHandle("dictionaryWithObjects:forKeys:"), objectsHandle, keysHandle));
     ObjC.ReleaseNSArrayItems(keysHandle);
     return dictionary;
 }
Exemplo n.º 4
0
        public static void Subscribe(NSObject obj, string selector, EventHandler callback)
        {
            var methods = GetMethods(obj, selector);
            methods.EventHandler += callback;

            if (!_delegates.ContainsKey(selector))
            {
                IntPtrHandler3 del = OnCallback;
                if (!ObjC.AddMethod(obj.ClassHandle, Selector.GetHandle(selector), del, "v@:@"))
                {
                    throw new InvalidOperationException("AddMethod failed for selector " + selector);
                }
                else
                {
                    _delegates[selector] = del;
                }
            }
        }
Exemplo n.º 5
0
        private static Methods GetMethods(NSObject obj, string selector)
        {
            Dictionary<IntPtr, Methods> dictionary;
            if (!_callbacks.TryGetValue(obj.Handle, out dictionary))
            {
                _callbacks[obj.Handle] = dictionary = new Dictionary<IntPtr, Methods>();
            }

            IntPtr selectorHandle = ObjC.GetSelector(selector);

            Methods methods;
            if (!dictionary.TryGetValue(selectorHandle, out methods))
            {
                dictionary[selectorHandle] = methods = new Methods(obj);
            }

            return methods;
        }
Exemplo n.º 6
0
 public void RemoveObserver(NSObject observer)
 {
     ObjC.MessageSend(Handle, Selector.GetHandle("removeObserver:"), observer.Handle);
 }
Exemplo n.º 7
0
 public void PostNotificationName(string name, NSObject obj = null)
 {
     ObjC.MessageSend(Handle, Selector.GetHandle("postNotificationName:object:"), name, obj == null ? IntPtr.Zero : obj.Handle);
 }
Exemplo n.º 8
0
 public void SetObjectForKey(NSObject obj, string key)
 {
     IntPtr handle = ObjC.ToNSString(key);
     ObjC.MessageSendIntPtr(Handle, Selector.GetHandle("setObject:forKey:"), obj.Handle, handle);
     ObjC.MessageSend(handle, Selector.ReleaseHandle);
 }
Exemplo n.º 9
0
 public static NSNotification FromName(string name, NSObject obj = null)
 {
     return Runtime.GetNSObject<NSNotification>(ObjC.MessageSendIntPtr(_classHandle, Selector.GetHandle("notificationWithName:object:"), name, obj == null ? IntPtr.Zero : obj.Handle));
 }
Exemplo n.º 10
0
 public static void UnsubscribeAll(NSObject obj)
 {
     _callbacks.Remove(obj.Handle);
 }
Exemplo n.º 11
0
 public static void Unsubscribe(NSObject obj, string selector, EventHandler<ButtonEventArgs> callback)
 {
     var methods = GetMethods(obj, selector);
     methods.EventHandlerInt -= callback;
 }
Exemplo n.º 12
0
 public static void Unsubscribe(NSObject obj, string selector, IntPtrHandler3 callback)
 {
     var methods = GetMethods(obj, selector);
     methods.ActionIntPtrIntPtrIntPtr -= callback;
 }
Exemplo n.º 13
0
 public static void Unsubscribe(NSObject obj, string selector, Action callback)
 {
     var methods = GetMethods(obj, selector);
     methods.Action -= callback;
 }
Exemplo n.º 14
0
 public string[] KeysForObject(NSObject obj)
 {
     var array = Runtime.GetNSObject<NSObject>(ObjC.MessageSendIntPtr(Handle, Selector.GetHandle("allKeysForObject:"), obj.Handle));
     return ObjC.FromNSArray(array.Handle);
 }
Exemplo n.º 15
0
 public string[] KeysForObject(NSObject obj)
 {
     return(ObjC.FromNSArray(Runtime.GetNSObject <NSObject>(ObjC.MessageSendIntPtr(Handle, Selector.GetHandle("allKeysForObject:"), obj.Handle)).Handle));
 }