UItableviewController doesn't load data
Hi guys i have a UITableviewcontroller class, i am calling it from otherview and pushing it on the navigationcontroller.
Streets_view_Controller_iPhone * street_controller = [[Streets_view_Controller_iPhone alloc]initWithStyle:UITableViewStylePlain];
street_controller.riding_number = [assignment objectForKey:@"Riding_Number"];
street_controller.polling_number = [assignment objectForKey:@"Poll"];
[self.navigationController pushView开发者_开发技巧Controller:street_controller
animated:YES];
and here is my tableview controller class "Streets_view_Controller_iPhone.m"
#import "Streets_view_Controller_iPhone.h"
@implementation Streets_view_Controller_iPhone
@synthesize riding_number;
@synthesize polling_number;
@synthesize data;
- (NSString *)dataFilePathwithFilename:(NSString*)name
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
return [documentsDirectory stringByAppendingPathComponent:name];
}
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:UITableViewStylePlain];
if (self)
{
// Custom initialization
}
return self;
}
- (void)dealloc
{
[riding_number release];
[polling_number release];
[data release];
[super dealloc];
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
self.title = @"Streets";
NSString * filepath = [self dataFilePathwithFilename:[NSString stringWithFormat:@"%@_%@.plist",self.riding_number,self.polling_number]];
NSLog(@"%@",filepath);
NSArray * streets = [[NSArray alloc] initWithContentsOfFile:filepath];
self.data = streets;
[streets release];
[super viewDidLoad];
[self.tableView reloadData];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 0;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// return [data count];
// NSLog(@"%d",[data count]);
return 2;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString * StreetLevelCell= @"StreetLevelCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:
StreetLevelCell];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:StreetLevelCell] autorelease];
// NSUInteger row = [indexPath row];
// NSDictionary * streets_data = [data objectAtIndex:row];
//cell.textLabel.text = [streets_data objectForKey:@"Street_name"];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.textLabel.text = @"test for streets";
return 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 editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
*/
/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{
}
*/
/*
// 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.
/*
<#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
// ...
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
*/
}
@end
But for some reason i amnot getting anything in the cell, just the title of the view i.e Streets . and empty table
Nothing will show up in your table because of the following:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 0;
}
You must have at least one section in your table for it to show any data. Try return 1;
and see if it works.
精彩评论