Je construis une application simple avec un onglet de barre personnalisée qui charge le contenu du ViewController
à partir d'un UITableView
situé dans un autre ViewController
. Cependant, chaque fois que j'essaie de faire défiler sur la tableview, j'obtiens une erreur exc_bad_access
. J'ai activé NSzombies
et garde malloc pour obtenir plus d'informations sur le problème.Erreur EXC_BAD_ACCESS sur un UITableView avec ARC?
Dans la console je reçois:
"message sent to deallocated instance 0x19182f20"
et après profilage je reçois:
# Address Category Event Type RefCt Timestamp Size Responsible Library Responsible Caller
56 0x19182f20 FirstTabBarViewController Zombie -1 00:16.613.309 0 UIKit -[UIScrollView(UIScrollViewInternal) _scrollViewWillBeginDragging]
Voici un peu du code de la ViewController où l'erreur se produit: .h :
#import <UIKit/UIKit.h>
#import "DataController.h"
@interface FirstTabBarViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> {
IBOutlet UITableView* tabBarTable;
}
@property (strong, nonatomic) IBOutlet UIView *mainView;
@property (strong, nonatomic) IBOutlet UITableView *tabBarTable;
@property (nonatomic, strong) DataController *messageDataController;
@end
fichier .m:
#import "FirstTabBarViewController.h"
#import "DataController.h"
@interface FirstTabBarViewController()
@end
@implementation FirstTabBarViewController
@synthesize tabBarTable=_tabBarTable;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)awakeFromNib
{
[super awakeFromNib];
self.messageDataController=[[DataController alloc] init];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [self.messageDataController countOfList];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"mainCell";
UITableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil){
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
};
NSString *expenseAtIndex = [self.messageDataController
objectInListAtIndex:indexPath.row];
[[cell textLabel] setText:expenseAtIndex];
return cell;
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the specified item to be editable.
return NO;
}
@end
Ce FirstTabBarViewController est chargé dans le MainViewController avec le Segue personnalisé suivant:
#import "customTabBarSegue.h"
#import "MainViewController.h"
@implementation customTabBarSegue
-(void) perform {
MainViewController *src= (MainViewController *) [self sourceViewController];
UIViewController *dst=(UIViewController *)[self destinationViewController];
for (UIView *view in src.placeholderView.subviews){
[view removeFromSuperview];
}
src.currentViewController =dst;
[src.placeholderView addSubview:dst.view];
}
@end
La classe Datacontroller est juste un NSMutableArray simple contenant des chaînes. J'utilise ARC, donc je ne comprends pas d'où vient l'erreur de gestion de la mémoire. Est-ce que quelqu'un a une idée?
Toute aide très appréciée;) Merci !!
« Quelqu'un at-il une idée? » - sans code? No. – Kreiri
S'il vous plaît code postal. –
désolé, je viens d'ajouter du code - merci pour votre aide – Spearfisher