2010-08-28 5 views
1

sous le code de test provoque EXC_BAD_ACCESS lorsqu'il est fait défiler plusieurs fois. quelqu'un aimerait me dire le problème?UITableView dans UINavigationController provoque EXC_BAD_ACCESS

-myview.h ------------------------------------------ ---------

@interface MyView : UINavigationController < UITableViewDataSource, UITableViewDelegate, UINavigationBarDelegate > 
{ 
    UITableView* mTableView; 
    NSMutableArray* data; 
} 

-myview.m ------------------------------ ---------------------

@implementation MyView 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    int th = self.navigationBar.frame.size.height; 
    int w = self.view.frame.size.width; 
    int h = self.view.frame.size.height; 

    mTableView = [[[UITableView alloc] initWithFrame: 
       CGRectMake(0.0f, th, w, h - th) style:UITableViewStylePlain] retain]; 
    mTableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | 
             UIViewAutoresizingFlexibleHeight; 
    mTableView.dataSource = self; 
    mTableView.delegate = self; 
    [mTableView setRowHeight:55]; 

    [self.view addSubview:mTableView]; 

    data = [[[NSMutableArray alloc] init] retain]; 

    for (int i = 0; i < 150; i++) 
    { 

     [data addObject:[NSDictionary 
     dictionaryWithObjects:[NSArray arrayWithObjects:@"good", [UIColor blackColor], nil] 

     forKeys:[NSArray arrayWithObjects:@"name", @"color", nil]]]; 
    } 
} 

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


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

- (UITableViewCell *)tableViewCellWithReuseIdentifier:(NSString *)identifier 
{ 
    UITableViewCell *cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier] autorelease]; 
    cell.textLabel.text = @"goooood"; 
    return cell; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"Cell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    if (cell == nil) 
     cell = [self tableViewCellWithReuseIdentifier:CellIdentifier]; 

    return cell; 
} 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
} 


- (void)viewDidUnload 
{ 
    [super viewDidUnload]; 
} 

- (void)dealloc 
{ 
    [super dealloc]; 
} 

- (BOOL)canBecomeFirstResponder 
{ 
    return YES; 
} 

@end 
+0

S'il vous plaît lire la documentation sur le formatage du code. Lorsque vous postez, il y a un lien sur la droite à propos du 'balisage'. –

+0

également, poster où le crash se produit et essayer de donner juste des morceaux de code pertinents – cobbal

+0

Qu'est-ce que cela a à voir avec C ou C++? –

Répondre

0

Vous devez avoir un contrôleur de vue qui contient votre point de vue de la table (il pourrait même être une sous-classe de UITableViewController). Je ne crois pas que UINavigationController ne veut pas être sous-classé comme vous l'avez fait. Si vous voulez un contrôleur de navigation, vous devez créer une instance de CustomTableViewController, contenant votre tableview, puis utilisez la méthode initWithRootViewController: de UINavigationController:

CustomTableViewController * ctvc = [[CustomTableViewController alloc] init]; 
UINavigationController * navigationController = [[UINavigationController alloc] initWithRootViewController:ctvc]; 
[ctvc release]; 

// Superview is where you want this added 
// probably your window in app did finish launching 
[superview addSubview:navigationController.view]; 

[navigationController release]; 
Questions connexes