How to assign a table view controller to a table view on iPhone?
- by Tattat
I have a CharTableController, View and TableView on my IB. The CharTableController is using "CharTableController" in class identity. And this is how I implemented in the .h, and I want use the "CharTableController" to control the table only:
@interface CharTableController : UITableViewController <UITableViewDelegate, UITableViewDataSource>{
// IBOutlet UILabel *debugLabel;
NSArray *listData;
}
//@property (nonatomic, retain) IBOutlet UILabel *debugLabel;
@property (nonatomic, retain) NSArray *listData;
@end
It is the .m:
#import "CharTableController.h"
@implementation CharTableController
@synthesize listData;
- (void)viewDidLoad {
//NSLog(@"bulll");
// [debugLabel setText:@"success"];
NSArray *array = [[NSArray alloc] initWithObjects:@"A", @"B", @"C", @"D", @"E", nil];
self.listData = array;
[array release];
[super viewDidLoad];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.listData 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 = [listData objectAtIndex:row];
}
return cell;
}
@end
In the IB, I already assign the CharTableController's view to Table View in IB. And Table View is under the View, in IB. After I run the program, I can see the table view, but I can't see any char in the table view, why? What's wrong with my code? thz.