Showing posts with label ipad. Show all posts
Showing posts with label ipad. Show all posts

Saturday, June 09, 2012

More CGSize/CGRect Stuff. Adding UIView to UIScrollView dynamically in a horizontal layout.

Ok so let's say I'm dynamically adding two UIViews to a UIScrollView in a horizontal layout. I want the second UIView to be places underneath the first UIView (with a padding of 2 pixels). Here's how I did it:

notes
1. myUIScrollView is the name of my UIScrollView
2. myView1 is the name of my first UIView.
3. myView2 is the name of my second UIView.

///
CGRect tempFrame = [myView1 frame]; //get frame/CGRect for myView1
[myUIScrollView addSubview:myView1]; //add myView1 to the UIScrollView

//get the size of myView1, and make the next Y co-ord its height+2.
int nextY = tempFrame.origin.y + myView1.bounds.size.height+2;

tempFrame = [myView2 frame]; //get the frame/CGRect for myView2
myView2.origin.y = nextY; //set the Y co-ord to that of myView1's height+2.
myView2.frame = tempFrame; //apply the frame to myView1.
[myUIScrollView addSubview:myView2]; //add myView2 to the UIScrollView object.

///


I'm sure there's a better way to do this. Somehow?

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.

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

Take a screen shot of your iPad/iPhone

To take a screenshot of your iPad/iPhone:

Press the power button on the top and the iPad button together. If done correctly, the screen should flash white. After that, the screen shot should be inside your 'photos' folder on your device.

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.

Sunday, February 06, 2011

Attribute libxml2 xpath iphone howto

Attribute libxml2 xpath howto:

Given the xml:

<yournodewithanattribute someattribute="some attribute value"></yournodewithanattribute>

To get the attribute value:

NSString *path = [NSString stringWithFormat:@"http://yourdomain/yourxmlfile.xml"];
NSURL *url = [NSURL URLWithString:path];
NSData *xmlData = [NSData dataWithContentsOfURL:url];
NSString *xPathQuery1;
NSArray *nodes1;

xPathQuery1 = @"//yournodewithanattribute";

nodes1 = (NSArray*)PerformXMLXPathQuery(xmlData, xPathQuery1);

for (NSDictionary *attrNodes1 in nodes1){
for (NSDictionary *nodeAttributeArray in [attrNodes1 objectForKey:@"nodeAttributeArray"]){
NSString *attributeName = [nodeAttributeArray objectForKey:@"attributeName"];
NSString *attributeValue = [nodeAttributeArray objectForKey:@"nodeContent"];
NSLog(@"Attribute Name: %@", attributeName);
NSLog(@"Attribute Value: %@", attributeValue);
}
}

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/

Tuesday, October 19, 2010

Tools to make apps quickly for mobile platforms

Making apps quickly (for non-programmers perhaps?) for the mobile platforms:


http://www.openplug.com/products/elips-studio
(Converts Flex apps to native apps for iPad, iPhone, Android, Windows Mobile and Symbian)

and

http://www.appcelerator.com/products/


I've yet to try these out; but they look promising.