2011-05-08 83 views
0

我遇到了一個我無法弄清楚的問題。當我運行我的應用程序並單擊其中一個表格視圖單元格時,單元格未加載與其關聯的視圖控制器。Tableviewcell無法加載

這裏是.M碼

#import "FirstViewController.h" 
#import "arraymap.h" 
#import "crackedmap.h" 
#import "crisismap.h" 
#import "firingrangemap.h" 

@implementation FirstViewController 
@synthesize imageArray, cellTextArray; 

- (void)viewDidLoad 
{ 
    self.title = @"Maps"; 
    imageArray = [[NSArray alloc] initWithObjects:@"1.png", @"1.png", @"1.png", @"1.png", nil]; 
    cellTextArray = [[NSArray alloc] initWithObjects:@"cell1", @"cell2", @"cell3", @"cell4", nil]; 
    [super viewDidLoad]; 
} 

- (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]; 
} 

/* 
// Override to allow orientations other than the default portrait orientation. 
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
// Return YES for supported orientations. 
return (interfaceOrientation == UIInterfaceOrientationPortrait); 
} 
*/ 

// Customize the number of sections in the table view. 
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    return 1; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    return 4; 
} 

// 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.backgroundView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:[imageArray objectAtIndex:indexPath.row]]] autorelease]; 

    UILabel *lab = [[UILabel alloc] initWithFrame:CGRectMake(10, 40, cell.frame.size.width-20, 35)]; 
    [lab setBackgroundColor:[UIColor clearColor]]; 
    [lab setText:[cellTextArray objectAtIndex:indexPath.row]]; 
    [cell.contentView addSubview:[lab autorelease]]; 

    // Configure the cell. 
    return cell; 
} 
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { 
    return 70; 
} 
/* 
// 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; 
} 
*/ 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UIViewController *viewController = nil; 
    switch (indexPath.row) { 
     case 0: 
      viewController = [[arraymap alloc] initWithNibName:@"arraymap" bundle:nil]; 
      break; 
     case 1: 
      viewController = [[crackedmap alloc] initWithNibName:@"crackedmap" bundle:nil]; 
      break; 
     case 2: 
      viewController = [[crisismap alloc] initWithNibName:@"crisismap" bundle:nil]; 
      break; 
     case 3: 
      viewController = [[firingrangemap alloc] initWithNibName:@"firingrangemap" bundle:nil]; 
      break; 
     default: 
      break; 
    } 
    [viewController setTitle:[NSString stringWithFormat:@"%i", indexPath.row+1]]; 
    [self.navigationController pushViewController:[viewController autorelease] animated:YES]; 
} 

- (void)didReceiveMemoryWarning 
{ 
    // Releases the view if it doesn't have a superview. 
    [super didReceiveMemoryWarning]; 

    // Relinquish ownership any cached data, images, etc that aren't in use. 
} 

- (void)viewDidUnload 
{ 
    [super viewDidUnload]; 

    // Relinquish ownership of anything that can be recreated in viewDidLoad or on demand. 
    // For example: self.myOutlet = nil; 
} 

- (void)dealloc 
{ 
    [cellTextArray release]; 
    [imageArray release]; 
    [super dealloc]; 
} 

@end 

回答

0

您是否嘗試過增加一個通話記錄,以確保的viewController不是零的副本?首先檢查,如果它是零,你知道你的開關是不正確的。