nsobject

show alertController from a custom class

若如初见. 提交于 2019-12-08 07:16:23
问题 I'm trying to show an AlertController from a class that I've made. Since AlertController is a subclass of UIResponder I'm using the following line of code that Xcode is suggesting me superclass?.presentViewController(alertController, animated: true, completion: nil) But I cannot compile because AnyClass? does not have any member presentViewController. My class is a subclass of NSObject. Any other solution? Thanks 回答1: Well you just need to find the topmost view controller and present the

Xamarin iOS delegate BaseType usage

我的未来我决定 提交于 2019-12-08 06:13:28
问题 I'm just wondering why delegate in binding iOS project has to use BaseType(typeof(NSObject)) attribute when it's iOS counterpart does not use NSObject iOS code: @protocol TestDelegate - (void)onSuccess:(NSString*)token; @end @interface Utility : NSObject @property (nullable, weak, getter = getTestDelegate, setter = setTestDelegate:) id<TestDelegate> delegate; @end Sharpie code with delegate to event mapping added: [Protocol, Model] public interface TestDelegate { [Export ("onSuccess:")] void

Objective C object by string name?

跟風遠走 提交于 2019-12-08 03:12:21
问题 Is it possible to find the object named with specific string. For example i can use that in php $objectname="foo"; $foo="bar"; echo $$objectname="bar"; is this possible? objectbyname would a proper function for this. 回答1: It could be possible if you stored named objects as properties or in some sort of dictionary. Then you could do something like this: // Put object into dictionary [dictionaryWithObjects setValue:someNamedObject forKey:@"someNamedObject"]; // and then retrieve it id object =

Objective C object by string name?

和自甴很熟 提交于 2019-12-07 17:57:34
Is it possible to find the object named with specific string. For example i can use that in php $objectname="foo"; $foo="bar"; echo $$objectname="bar"; is this possible? objectbyname would a proper function for this. It could be possible if you stored named objects as properties or in some sort of dictionary. Then you could do something like this: // Put object into dictionary [dictionaryWithObjects setValue:someNamedObject forKey:@"someNamedObject"]; // and then retrieve it id object = [dictionaryWithObjects valueForKey:@"someNamedObject"]; And I'm not sure ObjectiveC supports that level of

Inherit NSObject from C++ class

邮差的信 提交于 2019-12-07 08:58:38
问题 I'm emotionally attached to my C++ class, but I really want it to go into a tableview. Is there a way to subclass NSObject from a standard c++ class? this is what I tried to do: class Model : NSObject { public: NSString *key; }; The compiler did not like it one bit. It tells me the the base specifier must be a class. Is there any kind of sneaky thing I can do? Should I just make it a standard objective C++ object? 回答1: You cannot mix inheritance between C++ and Objective-C classes. Instead,

How do I get class from NSString?

…衆ロ難τιáo~ 提交于 2019-12-07 04:44:22
问题 for example, I have NSString *myClass = @"RootViewController" How do I get class from NSString? 回答1: Try this id obj= [[NSClassFromString(@"RootViewController") alloc] init]; 回答2: You can use Class class = NSClassFromString(@"RootViewController"); NSClassFromString Obtains a class by name. Class NSClassFromString ( NSString *aClassName ); Parameters aClassName The name of a class. Return Value The class object named by aClassName, or nil if no class by that name is currently loaded. If

How to add pointer to an NSObject custom subclass to an NSMutableArray?

余生颓废 提交于 2019-12-07 02:11:27
For the following code snippet from ViewController.m: - (IBAction)buttonAction:(id)sender { CustomButton *button = (CustomButton *)sender; button.associatedObject = [self.sourceOfObjects.objectArray lastObject]; [self.foo.arrayOfObjects addObject:button.associatedObject]; // this does not work? } • CustomButton is subclass of UIButton and has @property (nonatomic, strong) associatedObject that is a pointer to an object of type NSObject. • sourceOfObjects is a @property (nonatomic, strong) of self of type MyCustomObject, a subclass of NSObject. • objectArray is a @property (nonatomic, strong)

Do I need to call [super init] or [super initWithCoder], etc for NSObject

拥有回忆 提交于 2019-12-06 18:20:05
问题 Typically when I subclass from a UI class I will call the superclass initializer of interest. However, I'm not sure of the implementation details of NSObject , and it seems like there's not much going on in terms of member vars, so I wonder: do I need to call [super init] if my subclass extends NSObject ? 回答1: Technically, no. The documentation for -[NSObject init] says that The init method defined in the NSObject class does no initialization; it simply returns self . Because it is documented

Xamarin iOS delegate BaseType usage

左心房为你撑大大i 提交于 2019-12-06 15:44:11
I'm just wondering why delegate in binding iOS project has to use BaseType(typeof(NSObject)) attribute when it's iOS counterpart does not use NSObject iOS code: @protocol TestDelegate - (void)onSuccess:(NSString*)token; @end @interface Utility : NSObject @property (nullable, weak, getter = getTestDelegate, setter = setTestDelegate:) id<TestDelegate> delegate; @end Sharpie code with delegate to event mapping added: [Protocol, Model] public interface TestDelegate { [Export ("onSuccess:")] void OnSuccess (string token); } [BaseType(typeof(NSObject), Delegates = new string[] { "WeakDelegate" },

How to config NSURLSessionConfiguration into the NSObject class?

℡╲_俬逩灬. 提交于 2019-12-06 13:07:56
i want to get server response from NSObject when i m getting a response,it has return to viewController.as i implement on server call into NSObject class then i called to the NSObject method but before server response my NSString have been return as null . NSObject class : @interface getServerCallClassMethod : NSObject<NSURLSessionDelegate> { NSString *ResponceStr; } -(NSString *)getServerCall:(NSString *)mobleNo serverUrl:(NSString *)url; @end implement part : @implementation getServerCallClassMethod -(NSString *)getServerCall:(NSString *)mobleNo serverUrl:(NSString *)url{