0

데이터를 저장/검색하기 위해 호출되는 ClsDatabase 클래스가 있습니다. 또한 2 개의 전망이있다. 두 번째 뷰에는 ClsDataBase가 검색 한 내용을 기반으로 정보를 표시하는 테이블이 있습니다. 탭 막대가 2 개의보기를 제어합니다.sqlite3 + 테이블 + 탭 표시 줄을 사용할 때 XCode 오류 EXC_BAD_ACCESS

첫 번째보기가 표시된 상태에서 처음로드 할 수 있습니다. 그러나 두 번째보기를 선택하면 main.m의

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

의 오류 메시지 EXC_BAD_ACCESS가 표시됩니다.

나는 다른 프로젝트를 만들려고했으나 ClsDatabase를 사용하지 않고 테이블에 일부 dummmy 값만 인쇄했다. 하지의 경우 때문에 클래스의 확인은 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; 
} 

(2보기) .H

#import <UIKit/UIKit.h> 

#import "ClsDatabase.h" 

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

@end 

(2 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를 사용하려고 시도했을 때 두 번째 탭을 클릭했을 때 좀비 메시지 전에 앱이 종료되었습니다. –

+0

너무 많은 코드를 게시하고 있습니다. 줄이고 문제가있는 것으로 의심되는 부분을 보여주십시오. – Mundi

+0

예. 이미 최소로 축소되었습니다 ... 죄송합니다. –

답변

0

당신에게

을 ClsDatabase IB 및 스토리 보딩을 통해 수행해야하는 많은 일들을 코드에서 수행하고 있습니다.

indexPath.row0하고 당신의 arrDebtor가 비어 있고 휴대가 아직 생성되지 않은 경우 cellForRowAtIndexPath에있는 당신의 논리는, 첫 번째 행에 실패합니다. 그것은 EXC_BAD_ACCESS 오류를 설명합니다.

관련 문제