Thursday, September 16, 2010

Realise that you cannot tap on the last button for UIActionSheet? No fear.

I have this problem and after google. change the following

[menu showInView:self.view];

to

[menu showInView:[[[UIApplication sharedApplication] windows] objectAtIndex:0]];

The main reason is the tabcontroller will block 65% of the bottom view. although you cant see it, it is there. All thanks to the following blog.


http://runmad.com/blog/2010/04/uitabbarcontroller-and-uiactionsheet-65-percent-less-hit-point/

Tuesday, August 31, 2010

How to get composite name from ABRecordRef

ABRecordRef *person = (ABRecordRef *)[allPeople objectAtIndex:i];
// Display Name
NSString *displayName = (NSString *)ABRecordCopyCompositeName(person);

Trim String in Object C

This is how to trim a string and remove whitespace and newlines:

NSString *trimmedString = [dirtyString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];


For other character sets, refer to
http://developer.apple.com/iphone/library/documentation/Cocoa/Reference/Foundation/Classes/NSCharacterSet_Class/Reference/Reference.html#//apple_ref/doc/uid/20000157-SW5.

Sunday, August 15, 2010

how to rename in Mac OS

This is a command based solution. Works for Leopard, Snow Leopard or anything with ZSH

duck% zsh
duck% autoload zmv
duck% zmv '*.jpg' '$f:s/2_/518_/'

Sunday, July 25, 2010

How to show alert for iOS?

This is how you can show an alert box in iPhone or iPad app.


In your code include the following:

UIAlertView *alert = [[UIAlertView alloc] init];
[alert setTitle:@"Confirm"];
[alert setMessage:@"Buy This?"];
[alert setDelegate:self];
[alert addButtonWithTitle:@"Yes"];
[alert addButtonWithTitle:@"No"];
[alert show];
[alert release];

Then implement this in the delegate, in this case, the controller which calls UIAlertView.

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0)
{
// Yes, do something
NSLog(@"Yes!");
}
else if (buttonIndex == 1)
{
// No
NSLog(@"No!");
}
}

how to list files in iOS

This is how you can list files in your iPhone apps.

NSFileManager *manager = [NSFileManager defaultManager];
NSArray *fileList = [manager directoryContentsAtPath:documentsDirectory];
for (NSString *s in fileList){
NSLog(s);
}

How to test if file exist in iPhone iOS

BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:somePath];