here is my code for each view controller:
the root view .h:
@interface HappyRootViewController : UITableViewController
@property (nonatomic, retain) NSMutableArray *HappyArray;
root view .m:
@implementation HappyRootViewController
@synthesize HappyArray;
- (void)viewDidLoad
{
[superviewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.HappyArray = [NSMutableArrayarrayWithObjects:@"Dog?",@"Cat?",@"Snake?", nil];
[selfsetTitle:@"Happy Appy"];
[self.HappyArray addObject:@"Dog"];
[self.HappyArray addObject:@"Cat"];
[self.HappyArrayaddObject:@"Snake"];
}
// Return the number of rows in the section.
returnHappyArray.count;
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
MoodTableViewController *MVC = [[MoodTableViewControlleralloc] initWithNibName:@"MoodTableViewController"bundle:nil];
if ([[HappyArray objectAtIndex:indexPath.row] isEqual:@"Dog"]) {
MVC.happyInt = 0;
[MVC setTitle:[HappyArray objectAtIndex:indexPath.row]];
}
if ([[HappyArray objectAtIndex:indexPath.row] isEqual:@"Cat"]) {
MVC.happyInt = 1;
[MVC setTitle:[HappyArray objectAtIndex:indexPath.row]];
}
if ([[HappyArray objectAtIndex:indexPath.row] isEqual:@"Snake"]) {
MVC.happyInt = 2;
[MVC setTitle:[HappyArray objectAtIndex:indexPath.row]];
}
[self.navigationControllerpushViewController:MVC animated:YES];
table view .h
{
int happyInt;
}
@property (nonatomic, retain) NSMutableArray *DogArray;
@property (nonatomic, retain) NSMutableArray *CatArray;
@property (nonatomic, retain) NSMutableArray *SnakeArray;
@propertyint happyInt;
table view .m:
#import "MoodTableViewController.h"
@interfaceMoodTableViewController ()
@end
@implementation MoodTableViewController
//@synthesize MoodNumber, MoodName;
@synthesize happyInt;
@synthesize DogArray;
@synthesize CatArray;
@synthesize SnakeArray;
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
returnself;
}
- (void)viewDidLoad
{
MoodArray = [[NSMutableArrayalloc]
initWithObjects:@"Dog 1", @"Dog 2", nil];
DayArray = [[NSMutableArrayalloc]
initWithObjects:@"Cat 1", @"Cat 2", @"Cat 3", @"Cat 4",nil];
LocationArray = [[NSMutableArrayalloc]
initWithObjects:@"Snake 1", @"Snake 2", nil];
[superviewDidLoad];
}
- (void)viewDidUnload
{
// [self setMoodDetails:nil];
[superviewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
if (happyInt == 0)
return [MoodArray count];
if (happyInt == 1)
return [DayArray count];
if (happyInt == 2)
return [LocationArray count];
[self.tableViewreloadData];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//Create an NSString object that we can use as the reuse identifier
static NSString *CellIdentifier = @"Cell";
//Check to see if we can reuse a cell from a row that has just rolled off the screen
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
//If there are no cells to be reused, create a new cell
if (cell == nil) {
cell = [[UITableViewCellalloc] initWithStyle😟UITableViewCellStyleDefault) reuseIdentifier:CellIdentifier];
//Configure the cell
if (happyInt == 0)
cell.textLabel.text = [MoodArray objectAtIndex:indexPath.row];
if (happyInt == 1)
cell.textLabel.text = [DayArray objectAtIndex:indexPath.row];
if (happyInt == 2)
cell.textLabel.text = [LocationArray objectAtIndex:indexPath.row];
[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
//Set the text attribute to whatever we are currently looking at in our array
//cell.textLabel.text = [MoodArray objectAtIndex:indexPath.row];
//Set the detail disclosure indicator but not for this as its a detail
//cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
//Return the cell
return cell;
}
/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the specified item to be editable.
return YES;
}
*/
/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the item to be re-orderable.
return YES;
}
*/
#pragma mark - Table view delegate
/*
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Navigation logic may go here. Create and push another view controller.
//HappyRootViewController *HappyRVC = [[HappyRootViewController alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
// ...
// Pass the selected object to the new view controller.
//[self.navigationController pushViewController:HappyRVC animated:YES];
UITableViewCell *thisCell = [tableView cellForRowAtIndexPath:indexPath];
if (thisCell.accessoryType == UITableViewCellAccessoryNone) {
thisCell.accessoryType = UITableViewCellAccessoryCheckmark;
}
else
{
thisCell.accessoryType = UITableViewCellAccessoryNone;
}
}
- (UITableViewCellAccessoryType)tableView:(UITableView *)tableView accessoryTypeForRowWithIndexPath:(NSIndexPath *)indexPath {
//add your own code to set the cell accesory type.
return UITableViewCellAccessoryNone;
}
*/
}
@end