1

2番目のtableviewcontrollerを作成した後、このtableViewに接続されているtabbarItemをクリックすると、次の例外が発生しました。

2012-09-18 10:45:33.202 testStoryboard[5792:14203] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Requesting the window of a view (<UITableViewCell: 0x6b80190; frame = (0 0; 0 0); transform = [0, 0, 0, 0, 0, 0]; alpha = 0; opaque = NO; autoresize = W; layer = (null)>) with a nil layer. This view probably hasn't received initWithFrame: or initWithCoder:.' 
*** First throw call stack:
(0x14b2022 0xeb2cd6 0x145aa48 0x145a9b9 0x4b7c4 0x4d612 0x5246f 0x4c01b 0x6c494 0x9c838 0xb00e6 0xb03ce 0x9bcbd 0xaa6f1 0x53d21 0x14b3e42 0x1d83679 0x1d8d579 0x1d124f7 0x1d143f6 0x1da1160 0x25f30 0x148699e 0x141d640 0x13e94c6 0x13e8d84 0x13e8c9b 0x139b7d8 0x139b88a 0x15626 0x20fd 0x2065)
terminate called throwing an exception(lldb)

編集:これが私のコードです:

//  SecondTableViewController.m

#import "SecondTableViewController.h"

@interface SecondTableViewController ()

@end

@implementation SecondTableViewController

- (id)initWithStyle:(UITableViewStyle)style
{
     self = [super initWithStyle:style];
     if (self) {
        // Custom initialization
     }
     return self;
}

- (void)viewDidLoad
{
   [super viewDidLoad];

   //Initialize the array.
   myArray2 = [[NSMutableArray alloc] init];

   //Add items
   [myArray2 addObject:@"Iceland"];
   [myArray2 addObject:@"Greenland"];
   [myArray2 addObject:@"Switzerland"];
   [myArray2 addObject:@"Norway"];
   [myArray2 addObject:@"New Zealand"];
   [myArray2 addObject:@"Greece"];
   [myArray2 addObject:@"Rome"];
   [myArray2 addObject:@"Ireland"];

   //Set the title
   self.navigationItem.title = @"Countries";
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:   (UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

#pragma mark - Table view data source

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

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return [myArray2 count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if(cell == nil)
    {
        cell = [UITableViewCell alloc];
    }
    cell.textLabel.text = [myArray2 objectAtIndex:indexPath.row];
    return cell;
}

#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];
     */
}

@end

私はIOSを初めて使用しますが、誰かが私を正しい方向に向けることができますか?

4

1 に答える 1

5

セルの開始は完全ではありません。セルを割り当てるだけでなく、セルを初期化する必要があります。

cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
于 2012-09-18T18:45:08.000 に答える