Inheritance: IDisposable
Example #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;
 }
Example #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;
 }
Example #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;
 }
Example #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;
                }
            }
        }
Example #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;
        }
Example #6
0
 public void RemoveObserver(NSObject observer)
 {
     ObjC.MessageSend(Handle, Selector.GetHandle("removeObserver:"), observer.Handle);
 }
Example #7
0
 public void PostNotificationName(string name, NSObject obj = null)
 {
     ObjC.MessageSend(Handle, Selector.GetHandle("postNotificationName:object:"), name, obj == null ? IntPtr.Zero : obj.Handle);
 }
Example #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);
 }
Example #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));
 }
Example #10
0
 public static void UnsubscribeAll(NSObject obj)
 {
     _callbacks.Remove(obj.Handle);
 }
Example #11
0
 public static void Unsubscribe(NSObject obj, string selector, EventHandler<ButtonEventArgs> callback)
 {
     var methods = GetMethods(obj, selector);
     methods.EventHandlerInt -= callback;
 }
Example #12
0
 public static void Unsubscribe(NSObject obj, string selector, IntPtrHandler3 callback)
 {
     var methods = GetMethods(obj, selector);
     methods.ActionIntPtrIntPtrIntPtr -= callback;
 }
Example #13
0
 public static void Unsubscribe(NSObject obj, string selector, Action callback)
 {
     var methods = GetMethods(obj, selector);
     methods.Action -= callback;
 }
Example #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);
 }
Example #15
0
 public string[] KeysForObject(NSObject obj)
 {
     return(ObjC.FromNSArray(Runtime.GetNSObject <NSObject>(ObjC.MessageSendIntPtr(Handle, Selector.GetHandle("allKeysForObject:"), obj.Handle)).Handle));
 }