If BAD_ACCESS bothers you and you have no idea where it come from, try enabling NSZombies
Enabling NSZombies
The solution to overreleased objects are the zombies. When this feature is enabled, a dummy object (a zombie) is kept on the place of every released object, thus allowing to debug objects which were released already. Very easy to enable:
Double click your executable in the “Executables” in XCode
Open “Arguments” tab
In “Variables to be set in the environment” (that’s the list at the bottom, be careful which one you edit) click the “+” button and for name of the variable enter “NSZombieEnabled” and for value “YES”
Voila!
Now instead of wondering what’s going on and which exact object produced the problem, you’ll see exactly which class is the trouble maker, and you’ll debug it quite fast.
http://www.touch-code-magazine.com/how-to-debug-exc_bad_access/
Wednesday, October 13, 2010
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/
[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);
// 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.
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!");
}
}
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);
}
NSFileManager *manager = [NSFileManager defaultManager];
NSArray *fileList = [manager directoryContentsAtPath:documentsDirectory];
for (NSString *s in fileList){
NSLog(s);
}
Subscribe to:
Posts (Atom)
