I'm busy with some kind of Catalog for Iphone.
I want to show a list of Objects and when you touch one, you'll get extra information. Sounds easy, but it is driving me crazy. It doesn't matter which Object from the list I select, I always displays the SecondViewController.
Here's the code:
Rootviewcontroller.m:
When I touch Object 1, I'll get a new screen with the Title of Object 2 and the View of Object 1.
When I touch Object 2, I'll get the same.
Does anybody know what mistake I'm making?
Thanks in advance
I want to show a list of Objects and when you touch one, you'll get extra information. Sounds easy, but it is driving me crazy. It doesn't matter which Object from the list I select, I always displays the SecondViewController.
Here's the code:
Rootviewcontroller.m:
Code:
#import "RootViewController.h"
@implementation RootViewController
- (void)viewDidLoad {
[super viewDidLoad];
tableList = [[NSMutableArray alloc] init];
[tableList addObject:@"Object 1"];
[tableList addObject:@"Object 2"];
[self setTitle:@"Title for Nav bar"];
- (void)viewDidUnload {
// Release anything that can be recreated in viewDidLoad or on demand.
// e.g. self.myOutlet = nil;
}
#pragma mark Table view methods
- (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.textLabel.text = [tableList objectAtIndex:indexPath.row];
[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
return cell;
}
// Override to support row selection in the table view.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if ([[tableList objectAtIndex:indexPath.row] isEqual:@"Object 1"]);
{
SecondViewController *second = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
[second setTitle:@"Title of Object 1"];
[self.navigationController pushViewController:second animated:YES];
}
if ([[tableList objectAtIndex:indexPath.row] isEqual:@"Object 2"]);
{
ThirdViewController *third = [[ThirdViewController alloc] initWithNibName:@"ThirdViewController" bundle:nil];
[third setTitle:@"Title of Object 2"];
[self.navigationController pushViewController:third animated:YES];
}
}
When I touch Object 1, I'll get a new screen with the Title of Object 2 and the View of Object 1.
When I touch Object 2, I'll get the same.
Does anybody know what mistake I'm making?
Thanks in advance