I would like to update the interface in my application from AppDelegate, but whenever I call it like this:
Controller *object = [[Controller alloc] init]; [object methodHere];
It does not update the user interface. What am I doing wrong here? I set NSLog to find out if this is caused, and it does. Here is an example project that shows an error.
Edit: can someone just show me what I need to change in the project that I provided. I just don't know what to introduce into my project so that I can change the value of a simple NSTextField from another class.
, , , . testAppDelegate.h:
testAppDelegate.h
@interface testAppDelegate : NSObject <NSApplicationDelegate> { NSWindow *window; // You can make an IBOutlet to any kind of object you // want; it just a way for you to get a reference // in code to an object that has been alloc'd and // init'd already by the xib mechanism. IBOutlet Controller *controller; }
xib InterfaceBuilder Test App Delegate Controller ( xib).
testAppDelegate.m:
testAppDelegate.m
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification { // This is the key: // _Don't_ alloc/init a new controller object. The // objects in your xib are allocated and initialized // by virtue of being in that file. You just need to // give your AppDelegate a pointer to it, as above. [controller setTextValue:@"hello"]; }
[[Controller alloc] init], Controller, nib. , .
[[Controller alloc] init]
, Controller , NSArray. , nib, NSTextField, , - , , .
, , nib.
, . , appDelegate.h, .
: , , ( ).
.h
Controller* myController;
, , myController , , ,
[myController methodHere];
, . myController, .
, , - , . ,
-(returnType)callDelegateToDoSomething;
-(returnType)callDelegateToDoSomething:(id) sender;
, .
[sender methodHere];
, , . (, . , .)
Source: https://habr.com/ru/post/1793939/More articles:Is PCI compatible with image support (secure) not only with another subdomain, but also with a different domain? - htmlIs there a Python alternative for matlab cp2tform and imtransform? - pythonTablesorter configuration headers - jqueryHow to count the number of child nodes in xml root tag in flex? - flexС# несколько параметров выражения - c#global variable in asp-net mvc views - asp.net-mvcHow to use wildcards with LINQ? - linqSSO for oracle forms and Java EE - java-eeAn In-A-Way text display animation that mimics Magical Ink Writing in a magic book - ipadadding content to dynamic fancybox - jqueryAll Articles