0

データを保存/取得するために呼び出されるクラスClsDatabaseがあります。 また、2つのビューがあります。 2番目のビューには、ClsDataBaseが取得した情報に基づいて情報を表示するテーブルがあります。タブバーが2つのビューを制御します。sqlite3 +テーブル+タブバーを使用した場合のXCodeエラーEXC_BAD_ACCESS

これは最初に表示された最初のビューで読み込むことができます。 EXC_BAD_ACCESS:私は2番目のビューを選択した場合しかし、それはエラーメッセージが表示されてmain.mの

return UIApplicationMain(argc, argv, nil, NSStringFromClass([TestTabBarAppDelegate class])); 

で停止します。

私は別のプロジェクトを作成しようとしましたが、ClsDatabaseを使わずにテーブルにダムミーの値をいくつか印刷しています。わからない場合はその理由クラスのClsDatabase

AppDelegate.m

#import "TestTabBarAppDelegate.h" 
#import "TestTabBarFirstViewController.h" 
#import "TestTabBarSecondViewController.h" 

@implementation TestTabBarAppDelegate 

@synthesize window = _window; 
@synthesize tabBarController = _tabBarController; 

- (void)dealloc 
{ 
    [_window release]; 
    [_tabBarController release]; 
    [super dealloc]; 
} 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; 
    UIViewController *viewController1 = [[[TestTabBarFirstViewController alloc] initWithNibName:@"TestTabBarFirstViewController" bundle:nil] autorelease]; 
    UIViewController *viewController2 = [[[TestTabBarSecondViewController alloc] initWithNibName:@"TestTabBarSecondViewController" bundle:nil] autorelease]; 
    self.tabBarController = [[[UITabBarController alloc] init] autorelease]; 
    self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, nil]; 
    self.window.rootViewController = self.tabBarController; 
    [self.window makeKeyAndVisible]; 
    return YES; 
} 

(第二ビュー)の.h

#import <UIKit/UIKit.h> 

#import "ClsDatabase.h" 

@interface TestTabBarSecondViewController : UIViewController<UIApplicationDelegate, UITabBarControllerDelegate>{ 
    NSArray *arrDebtor; 
    ClsDatabase *dbDebtor; 
} 

@end 

(第二view.m)

#import "TestTabBarSecondViewController.h" 

@implementation TestTabBarSecondViewController 

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) { 
     self.title = NSLocalizedString(@"Second", @"Second"); 
     self.tabBarItem.image = [UIImage imageNamed:@"second"]; 
    } 
    return self; 
} 

- (void)viewDidLoad 
{  
    NSString *strSql; 
    dbDebtor = [[ClsDatabase alloc] initWithDbName:@"Debt"]; 
    arrDebtor = [[NSArray alloc] init]; 

    strSql = [NSString stringWithFormat:@"SELECT * FROM Debtor"]; 
    arrDebtor = [dbDebtor ReturnQueryArray:strSql]; 

    [super viewDidLoad]; 
} 

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

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section    { 
    if ([arrDebtor count] == 0) { 
     return 1; 
    } 
    else { 
     return [arrDebtor count]; 
    } 
} 

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

    if ([arrDebtor count] == 0) { 
     if (indexPath.row == 1) { 
      if (cell == nil) 
      { 
       cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier] autorelease]; 
     } 
      cell.textLabel.text = [NSString stringWithFormat:@"No tables or records found"]; 
      return cell; 
     } 
    } 
    else { 
     if (cell == nil) 
     { 
      cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier] autorelease]; 
     } 
     NSMutableDictionary *dictDebtor = [arrDebtor objectAtIndex:indexPath.row]; 
     cell.textLabel.text = [dictDebtor valueForKey:@"Name"]; 
     return cell; 
    } 
} 
+0

このタイプのエラーを追跡するためにNSZombieEnabledを使用しようとしたとき、アプリケーションは2番目のタブをクリックしたときにゾンビメッセージの前に終了しました。 –

+0

コードが多すぎます。それを削減し、問題が含まれていると思われる部分を表示してください。 – Mundi

+0

はい。すでに最小限に抑えられています...ごめんなさい。 –

答えて

0

ますIBやストーリーボードでやるべきことがたくさんあります。

indexPath.row0であり、あなたのarrDebtorが空になると、あなたのセルがまだ作成されていない場合cellForRowAtIndexPathであなたのロジックは、最初の行に失敗します。それはEXC_BAD_ACCESSエラーを説明します。

関連する問題