Hey!
I'm a beginner iPhone programmer, and I have a problem.
I've made a navigation based application.
I populated the TableView from an array with no problem.
I also made my cells lead to an other view when they are being clicked.
So basically, there are like 10 cells, and each of them leads to another view (SubViewController).
Now I wanted to do the same thing on all the other views (populating a tableview and make the cells lead to an other view).
But that's when the problem came. I made a tableview and tried to populate it, but when I run my application in the simulator, the 2nd tableview is just the same as the 1st.
So, to make it clear.
There is RootViewController with a table, containing these: Colors, Cars, Countries and so on.
Obviously, the cell containing 'Colors' leads to a view called Colors. On that view, I wanted to show a new tableview containing Red, Blue, Black and so on, but although I think I did everything right, it just keeps showing Colors, Cars and Countries. What could went wrong? Is it a common problem?
I basically just copy-pasted everything (that has something to do with the tableview) from the RootViewController, to make it easier. Of course I changed the name of the arrays and possibly everything. But nothing helped. What could be the source of the problem?
I'll write a part of the code down here and hopefully y'all can help me.
RootViewController.h
RootViewController.m
(and i write a lot of these with "else if", i'm not going to copy it)
Colors.h
Colors.m
And basically that's. I'm really a beginner, so please excuse me if the problem is just obvious. I don't know, maybe the problem is that a NavigationController contains something built in which is needed to make a tableview, and I forgot to build that in Colors.
Thank you If you read this through and try to help me.
Sorry for my english, if there are mistakes in it. I'm hungarian.
I'm a beginner iPhone programmer, and I have a problem.
I've made a navigation based application.
I populated the TableView from an array with no problem.
I also made my cells lead to an other view when they are being clicked.
So basically, there are like 10 cells, and each of them leads to another view (SubViewController).
Now I wanted to do the same thing on all the other views (populating a tableview and make the cells lead to an other view).
But that's when the problem came. I made a tableview and tried to populate it, but when I run my application in the simulator, the 2nd tableview is just the same as the 1st.
So, to make it clear.
There is RootViewController with a table, containing these: Colors, Cars, Countries and so on.
Obviously, the cell containing 'Colors' leads to a view called Colors. On that view, I wanted to show a new tableview containing Red, Blue, Black and so on, but although I think I did everything right, it just keeps showing Colors, Cars and Countries. What could went wrong? Is it a common problem?
I basically just copy-pasted everything (that has something to do with the tableview) from the RootViewController, to make it easier. Of course I changed the name of the arrays and possibly everything. But nothing helped. What could be the source of the problem?
I'll write a part of the code down here and hopefully y'all can help me.
RootViewController.h
Code:
#import <UIKit/UIKit.h>
@interface RootViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> {
NSArray *stuff;
}
@property (nonatomic, retain) NSArray *stuff;
@end
RootViewController.m
Code:
#import "Colors.h"
#import "Cars.h"
#import "Countries.h"
@implementation RootViewController
@synthesize stuff;
- (void)viewDidLoad
{
NSArray *array = [[NSArray alloc] initWithObjects:@"Colors",@"Cars", @"Countries", nil];
self.stuff = array;
[array release];
[super viewDidLoad];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.stuff count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SimpleTableIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:SimpleTableIdentifier] autorelease];
}
NSUInteger row =[indexPath row];
cell.textLabel.text = [stuff objectAtIndex:row];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
if ([[stuff objectAtIndex:indexPath.row] isEqual:@"Colors"])
{
Colors *colors = [[Altalanos alloc] initWithNibName:@"Colors" bundle:nil];
[self.navigationController pushViewController:altalanos animated:YES];
[colors release];
}
Colors.h
Code:
#import "RootViewController.h"
@interface Colors : RootViewController <UITableViewDelegate, UITableViewDataSource> {
NSArray *colorsSub;
}
@property (nonatomic, retain) NSArray *colorsSub;
@end
Code:
- (void)viewDidLoad
{
NSArray *arrayColors = [[NSArray alloc] initWithObjects:@"Red",@"Blue", nil];
self.colorsSub = arrayColors;
[arrayColors release];
[super viewDidLoad];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.colorsSub count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *ColorsIdentifier = @"ColorsIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ColorsIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ColorsIdentifier] autorelease];
}
NSUInteger row =[indexPath row];
cell.textLabel.text = [colorsSub objectAtIndex:row];
return cell;
}
And basically that's. I'm really a beginner, so please excuse me if the problem is just obvious. I don't know, maybe the problem is that a NavigationController contains something built in which is needed to make a tableview, and I forgot to build that in Colors.
Thank you If you read this through and try to help me.
Sorry for my english, if there are mistakes in it. I'm hungarian.
Last edited by a moderator: