Showing posts with label xcode. Show all posts
Showing posts with label xcode. Show all posts

Tuesday, September 01, 2015

Run iPhone simulator from command line (Xcode 6)

From the command line (terminal):


open "/Applications/Xcode.app/Contents/Developer/Applications/iOS Simulator.app"


Or in newer versions:

open "/Applications/Xcode.app/Contents/Developer/Applications/Simulator.app"

Saturday, June 09, 2012

UINavigationController in XCode 4.2

A lot of tutorials for UINavigationController don't work for XCode 4.2. So...

I found this decent tutorial on how to implement a UINavigationController:

http://www.techotopia.com/index.php/Creating_a_Navigation_based_iOS_5_iPhone_Application_using_TableViews

Friday, April 15, 2011

Hide Status Bar in iPhone

In applicationDidFinishLaunching:


[[UIApplication sharedApplication] setStatusBarHidden:YES];

GADRequest Test Mode (isTesting)

To set the GADRequest into test mode you are told to set 'isTesting.' This can be done by loading your GADBannerView like so:

GADRequest *r = [[GADRequest alloc] init];
r.testing = YES;
[bannerView_ loadRequest:r];

Apparently you don't need to care about this when you submit you app, since AdMob will never be in test mode when deployed on a real device.

Sunday, April 10, 2011

Sqlite database not accessible after change of bundle identifier

Noticed the strangest behavior today.

After I changed the bundle identifier in my XCode project, the sqlite database no longer had the tables I'd created before. Changing the bundle identifier back made the tables accessible again. Even from the command line interface they had disappeared.

The way to resolve it was to re-enter the data :\

Not sure why this happened or how it could be easier to migrate the data over yet. I need to investigate this more.

Saturday, April 09, 2011

iPhone force rotate to portrait

[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortrait];

//Probably works for iPad too

Saturday, February 26, 2011

Sunday, February 13, 2011

Change text and action of UIBarButtonItem

To change the text and the action of a UIBarButtonItem is no straightforward thing.

1. In Interface Builder, make sure the UIBarButtonItem is of Identifier: Custom

2. Do the usual hooking up of the button via an IBOutlet.

3. Use this code (where 'myBarButtonItem' is the existing button that has already been hooked up via an IBOutlet, and 'doSomeNewAction' is the new action I wish for the button to perform):

UIBarButtonItem *myNEWBarButtonItem = self.myBarButtonItem;
[myNEWBarButtonItem setTarget:self];
[myNEWBarButtonItem setTitle:@"Do Some New Action"];
[myNEWBarButtonItem setAction:@selector(doSomeNewAction:)];

Wednesday, February 09, 2011

Toolbar disappears on rotate (ipad/iphone/ios)

In interface viewer, my toolbar was disappearing when I rotated the interface.

To solve it, I had to adjust the 'Autosizing' property inside the 'Toolbar Size' tab.

Saturday, February 05, 2011

loaded the "xxxx" nib but the view outlet was not set

I was tired at night and was getting the error:

loaded the "xxxx" nib but the view outlet was not set

It was simply because I forgot to connect the View. To solve it:

1. Open the nib in "Interface Builder"

2. Right click on "File's Owner"

3. Connect the 'view' outlet to the respective view.

4. Important -> Save the interface.

It should work now :)

Sunday, January 30, 2011

gcc-4.2 failed with exit code 1

When compiling an iPhone app. I got gcc-4.2 failed with exit code 1

This was a strange one. Which I still don't fully understand.

It was happening because I had a duplicate global variable in two different .m files.

This was found by right clicking on the error message and selecting "Open These Latest Results as Transcript Text File." This revealed something like:

"ld: duplicate symbol _mouseSwiped"

Removing the duplicate symbol solved it for me.

Although I don't think I am properly understanding how Objective C works yet.

Saturday, January 29, 2011

"does not have an outlet named" problem in XCode/Interface Builder

I was getting the error "Blah blah does not have an outlet named blahblah" in Interface Builder.

After clicking on 'reload all class files'

I guess the problem was caused because I moved my user directory from one drive to another.

To solve it, I clicked on "File -> Read Class Files" then located the correct view controller class that I was trying to link to.

Wednesday, January 12, 2011

Loop alphabet objective c

Objective C makes it easy:

NSMutableArray *alphabetArray;
alphabetArray = [[NSMutableArray alloc] init];
for(char c = 'A'; c <= 'Z'; c++)
{
[alphabetArray addObject:[NSString stringWithFormat:@"%c", c]];
}

Or if you want to do lower case:

NSMutableArray *alphabetArray;
alphabetArray = [[NSMutableArray alloc] init];
for(char c = 'a'; c <= 'z'; c++)
{
[alphabetArray addObject:[NSString stringWithFormat:@"%c", c]];
}

Saturday, January 08, 2011

App has exited with status 5 (After upgrading XCode)

After upgrading my XCode to a newer version, I tried to compile and run some iPad code that was previously working... but after the upgrade I was getting the message "App has exited with status 5"

I solved this by setting the "Installation Directory" which had somehow become corrupted. I set it to "@executable_path/../Frameworks" and then all was fine. As illustrated:

Thursday, January 06, 2011

setfont is deprecated iPhone

Yes indeed it is.

Now this:
//cell.font=[UIFont fontWithName:@"Trebuchet MS" size:20.0];

Should become this instead:
cell.textLabel.font = [UIFont fontWithName:@"Trebuchet MS" size:20.0];

libxml2 ios example. libxml2 in xcode

This is a bit of a messy post, but it involves getting apps written using libxml2 to compile in Xcode.

1. Firstly, you'll need the libxml2 framework for Snow Leopard (and annoyingly, gcc to compile it).

You can download the latest libxml2 (get the .tar.gz) from here: ftp://xmlsoft.org/libxml2

Extract the files. Then do a

sudo ./configure
sudo make install

Boom. You're getting there. You can now open your Xcode environment.

2. When you first try to compile, you might get something like "libxml2 _xmlXPathNewContext referenced from" as an error.

This is because the library is not linked in the project yet.

You can link it by right clicking on the "Frameworks" folder, then "Add" -> "Existing Framework"

If libxml2 is installed on your system, you should be able to see it in the drop down box. As in the following screenshot:




3. The other thing that must be done. Is to put the string "/usr/include/libxml2/" in your search paths for your project. This is found by left clicking on your main project. Then clicking the blue 'info' button, followed by the 'build' tab.



I hope this helps someone save hours of frustration and searching like I did.

Gcc on Snow Leopard

Yesterday I was trying to compile something that required gcc. To my horror gcc was not installed on my Snow Leopard.

Strange, because it is said that gcc comes as part of the developer tools.

Apparently not. I needed to install the developer tools from the Snow Leopard CD itself. Which worked.

Which caused a problem of me losing my entire SDK for iOS. Which needed to be installed once again. (2.9 gig download - ouch)

This nice blog has a link to all the different XCode downloads for iPhone/iPad SDK, etc: http://chris-fletcher.com/2010/08/28/howto-install-iphone-sdk-2-0-3-1-for-xcode-3-2/