2011-06-10 62 views
0

嗨,大家好我有一个UITableviewcontroller类,我从其他视图调用它并将它推到navigationcontroller上。UItableviewController不加载数据

​​

这里是我的tableview控制器类 “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 

但由于某些原因,我amnot得到任何东西在细胞中,视图即街道的只是标题。和空表

回答

2

什么都不会显示在您的表,因为以下内容:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    return 0; 
} 

您必须在您的表中至少一个部分为它显示任何数据。尝试return 1;,看看它是否有效。

+0

哦主!从来没有注意到它 – Amrit 2011-06-10 15:17:10

+0

谢谢,我知道我是愚蠢的问这样的事情 – Amrit 2011-06-10 15:17:46