Flipkart Search

Search This Blog

Friday, May 1, 2009

// This will get a random number between 0 and 9
int ranX = arc4random() % 10;

Cocos2d Rectangle Rectangle Collision Detection

- (BOOL) rect:(CGRect) rect collisionWithRect:(CGRect) rectTwo
{
float rect_x1 = rect.origin.x;
float rect_x2 = rect_x1+rect.size.width;

float rect_y1 = rect.origin.y;
float rect_y2 = rect_y1+rect.size.height;

float rect2_x1 = rectTwo.origin.x;
float rect2_x2 = rect2_x1+rectTwo.size.width;

float rect2_y1 = rectTwo.origin.y;
float rect2_y2 = rect2_y1+rectTwo.size.height;

if((rect_x2 > rect2_x1 && rect_x1 < rect2_x2) &&(rect_y2 > rect2_y1 && rect_y1 < rect2_y2))
return YES;

return NO;
}

iPhone SDK Show Activity Indicator in the Status Bar

[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;


iPhone SDK dismiss the keyboard

Q: How do you remove the keyboard when the Return/Done button is pressed?
A: Set the delegate on the text field that will bring up the keyboard. Add the following selector to the object that you set to be the delegate.

- (BOOL) textFieldShouldReturn:(UITextField *) textField
{
[textField resignFirstResponder];

return YES;
}

iPhone SDK Load Text File Into NSString

NSString *path = [[NSBundle mainBundle] pathForResource:@"file" ofType:@"txt"]; 
NSString *fileText = [NSString stringWithContentsOfFile:path];


No comments: