Thursday, January 27, 2011

XCode tips and Tricks

Adding an icon to the table view

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

NSString *imgSource = [[NSBundle mainBundle] pathForResource:@"ICN1" ofType:@"jpg"];

UIImage *img = [UIImage imageWithContentsOfFile: imgSource];

cell.image = img;

}

Text alignment

cell.textLabel.textAlignment = 2 ;

Showing Alert

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Blue View Button Pressed" message:@"You Pressed a button on the blue view" delegate:nil cancelButtonTitle:@"Yep, I did." otherButtonTitles:nil];

[alert show];

[alert release];

Animating Images

// create the view that will execute our animation

UIImageView* ImageView = [[UIImageView alloc] initWithFrame:self.view.frame];

// load all the frames of our animation

ImageView.animationImages = [NSArray arrayWithObjects:

[UIImage imageNamed:@"1.png"],

[UIImage imageNamed:@"2.png"],

[UIImage imageNamed:@"3.png"],

nil];

// all frames will execute in 1.75 seconds

ImageView.animationDuration = 1.75;

// repeat the annimation forever

ImageView.animationRepeatCount = 0;

// start animating

[ImageView startAnimating];

// add the animation view to the main window

[self.view addSubview:ImageVie