Show Description of our Heroes
1. We are going to display a description of the hero when the his row is touched. For that we need to display another view with a UITextView. Open HeroViewController.h and add a variable of type UITextView:
@interface HeroViewController : UIViewController {
UITextView *heroDesciption;
}
@property (nonatomic, retain) IBOutlet UITextView *heroDesciption;
@end
2. Next modify the HeroViewController.m file to synthesize heroDescription.
3. Now we modify the view HeroViewController.xib. Drag a UITextView to the View Window. Then connect up the UITextView to our heroDescription.
4. Lastly we are going to implement the behaviour that will display the HeroViewController view. Open RootViewController.m and modify didSelectRowAtIndexPath as follows:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { Hero *hero = (Hero *)[Heroes objectAtIndex:indexPath.row]; HeroViewController *heroViewController = [[HeroViewController alloc] initWithNibName:@"HeroViewController" bundle:nil]; // Pass the selected object to the new view controller. [self.navigationController pushViewController:heroViewController animated:YES]; heroViewController.title = hero.name; heroViewController.heroDesciption.text = hero.desc; [heroViewController release]; }
And you are done. Save and run the application. Clicking on a name should slide a new view in that displays a description of the superhero you clicked on.

No comments:
Post a Comment