I create an OS X app in XCode. but it doesn't work. When i launch this app in XCode, my window does not appear. and there is any log. I think the problem is 'Appdelegate is not called'. I already check my referencing outlets, but there is nothing special. I also check my storyboard entry point(initial controller).
Here is my Appdelegate.
Appdelegate:
enter image description here
enter image description here
- (void)applicationWillFinishLaunching:(NSNotification *)notification {
NSLog(#"applicationWillFinishLaunching");}
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
// Insert code here to initialize your application
NSLog(#"applicationDidFinishLaunching");}
I'm not good at English. sorry.
What can I do?
Related
I've recently been trying to create an application on Xcode 9.4.1 with the Objective-C programming language.
I am trying to make the application work from the menu bar rather than a full app.
However, I have only managed to make the Menu items show up and have no idea how to add actions such as a web link to the buttons.
Can anyone help with this? All I want is to add actions to the buttons using code.
P.S. I am not using storyboards.
Without providing what you've done so far it seems like you're asking for complete code, nevertheless I happen to have an old project that does it. In the app delegate you do something like this: in the barItemAction method you can do whatever you need to perform
#interface AppDelegate ()
#property NSStatusItem *barItem ;
#end
#implementation AppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
self.barItem = [NSStatusBar.systemStatusBar statusItemWithLength:NSVariableStatusItemLength];
self.barItem.button.title = #"🚀";
[self.barItem setAction:#selector(barItemAction)];
// Insert code here to initialize your application
}
-(void)barItemAction {
NSLog(#"🚀 button was clicked ");
}
Here is my problem. I have an NSTextField connected to my app delegate. Then i have a CustomView in my MainManu.xib associated with a new class i created, "myView", sublass of NSView. finally a Button that trigger an action declared in myView.h. (i drag n drop from button to the custom view and selected the action pushFromView)
This action is implemented in myView.m in this way:
-(IBAction)pushFromView:(id)sender{
[self.myApp getMeFromView];
}
myApp is an instance of AppDelegate that contain the method getMeFromView which is supposed to get the text from the textfield and log it.
#import "GTAppDelegate.h"
#implementation GTAppDelegate
#synthesize myText;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Insert code here to initialize your application
}
-(void)getMeFromView{
NSLog(#"valuefromView= %d",[myText intValue]);
}
#end
Now anytime i press the button it trigger the method but even if the textfield is filled with numbers it returns me zero. Instead if i create a button connected with an action in appDelegate it works properly.
an instance of myApp is declared in myView header and the property as well.
Im kinda rookie, so maybe I explained myself in a non proper way. I hope you can get it.
Thanks in advance for your help.
Luca
Use just [myApp getMeFromView] instead of [self.myApp getMeFromView].
I have an iPad app created using XCode 4 with Storyboard. I have a UITableViewController with the interface defined as such:
#interface CustomerViewController : UITableViewController <UITextFieldDelegate>
In the .m file, I have a code snippet as:
- (BOOL) textFieldShouldReturn:(UITextField *)textField {
if(textField == businessName) {
[email becomeFirstResponder];
return true;
}
The method 'textFieldShouldReturn' does NOT get executed. What else needs to be done? (BTW... I have never been able to get this to work in a iPad app, but always successful in a iPhone app)
In the textFieldShouldReturn method, you're testing if the textField is equal to businessName. I'm assuming that's a UITextField object, but you have to set the delegate to receive callbacks. Just a simple self.businessName.delegate = self; when you create the TextField.
Another tip, I'd recommend calling it something like businessNameTextField. It's easier to read throughout your code.
You have to set the view controller as the delegate of the text field, just declaring that you conform to the protocol isn't enough. If it works in the iPhone but not iPad, then the chances are you haven't linked the delegate outlet in the iPad storyboard, but you have in the iPhone.
Hi I'm having a weird problem.
My app is based on the samplecode of "PageControl" (the Apple example).
It uses a horizontal scrollview in which most of the stuff is happening.
At he bottom I have a UIToolbar from which I call a modal viewcontroller.
On XCode 4 everything worked like a charm, after the upgrade to XCode 4.2 (with the new SDK) I get a "exc_bad_access" on dimissModalViewcontroller.
The funniest thing is that it does not happen rightaway but only after 2 or 3 times presenting and dismissing the modalViewcontroller.
To simplify things I went back to the original samplecode and tried to implement the modalVieWcontroler in that context. No luck so far.
In the original PageControl Code I changed the type of "ContentController" from NSObject to UIViewController like so:
#interface ContentController : UIViewController
{
NSArray *contentList;
}
I call presentModalViewcontroller in a sub class (from ContentController) named PhoneContentController like so:(I use a notification so I can call it from anywhere)
-(void) showExplanationsModal:(NSNotification*)notification{
ExplanationsViewController *xplViewController = [[[ExplanationsViewController alloc] initWithNibName:#"Explanations" bundle:nil]autorelease];
[self presentModalViewController:xplViewController animated:YES];
}
The dismissal of the modalViewcontroller is called from the modal view itself like so:
(the notification is used tot initiate some other stuff)
- (IBAction)onClose
{
[self dismissModalViewControllerAnimated:YES];
[[NSNotificationCenter defaultCenter]postNotificationName:#"dismissExplanationsModal" object:self];
}
This code works fine with iOS4 SDK but renders occasional excec_bad_access with iOS5 SDK.
When I compile the app with iOS4 SDK it also rus fine on iOS5 devices.
I tried using Zombies but this does not point to a specific over-released object.
I'm sort of stuck on this one for a few days already ...
I have put up a copy of a sample project that illustrates the problem here http://www.sesni.biz/pagecontrol.zip
It seems for me that problem is in the onClose method. Try first sending the message, without the object (this object will be invalidated soon).
- (IBAction)onClose
{
[[NSNotificationCenter defaultCenter]postNotificationName:#"dismissExplanationsModal" object:nil];
[self dismissModalViewControllerAnimated:YES];
}
Found the problem: I changed the type of ContententController from NSObject to UIViewcontroller. This worked fine with the iOS4 SDK but crashes with iOS5 SDK.
I'm having problems getting my iPad app to detect its interfaceOrientation in the first UIViewController I initialize (in code). In fact, if I trace for application.statusBarOrientation, that too returns 1 (UIInterfaceOrientationPortrait) even if I launched in landscape.
If I trace self.interfaceOrientation in my first UIViewController, it remains 1 until it gets to viewWillDisappear... Which is unfortunately too late!
Here's some code (even though there's not much to see):
In my appDelegate I have this:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// show loading screen first
[window addSubview:loadingScreenViewController.view];
[window makeKeyAndVisible];
NSLog(#"applicationDidBecomeActive:statusBarOrientation = %d", application.statusBarOrientation);
return YES;
}
which traces 1 (portrait), even though I clearly see the status bar is landscape... and in the first view controller I have this:
- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(#"self.interfaceOrientation = %d", self.interfaceOrientation);
}
which also traces 1, even in landscape mode.
Any ideas? Stumped here!
Thanks :)
:-Joe
Here is the answer... Somewhat: (from Apple Dev Forums): ....
"The app is always loaded as if the device is portrait, and then if the device is really landscape the app is told that the device has rotated. This is done so that nibs and code only need to create their UI in one orientation. Otherwise it might be necessary to have two UI layouts for each nib." .... it's not the answer I'd have liked, but that's how iOS works unfortunately!
What does the app delegate report in applicationDidFinishLaunching? Because if it reports the correct value, you can always access the delegate to check the orientation.