Hey,
I've got a TableView and I want that when I tap on one cell another TableView loads up.
So I wrote in my RootController.h:
Code:
#import <UIKit/UIKit.h>
#import "SecondViewController.h"
@interface RootViewController : UITableViewController <UITextFieldDelegate> {
NSMutableArray *tableList;
}
@end
and in my .m :
Code:
@implementation RootViewController
#pragma mark -
#pragma mark View lifecycle
- (void)viewDidLoad {
[super viewDidLoad];
tableList = [[NSMutableArray alloc] init];
[tableList addObject: @"The View"];
[self setTitle: @"Table View"];
}
#pragma mark -
#pragma mark Table view data source
// Customize the number of sections in the table view.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [tableList count];
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
[cell setText:[[tableList objectAtIndex:indexPath.row]retain]];
[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
return cell;
}
#pragma mark -
#pragma mark Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if ([[tableList objectAtIndex:indexPath.row] isEqual: @"The View"]) {
SecondViewController *second = [[SecondViewController alloc] initWithNibName:nil bundle:nil];
[second setTitle:@"The View"];
[self.navigationController pushViewController:second animated:YES];
}
}
#pragma mark -
#pragma mark Memory management
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Relinquish ownership any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Relinquish ownership of anything that can be recreated in viewDidLoad or on demand.
// For example: self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
@end
In my SecondViewController I've done the same (of course I adjusted it), but when I tap on one cell in the first ViewController only the empty SecondView loads up.
What's wrong?