Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用sqlite3+;时,XCode错误EXC_BAD_访问;表+;标签栏_Xcode_Uitableview_Uitabbarcontroller_Xcode4.2_Exc Bad Access - Fatal编程技术网

使用sqlite3+;时,XCode错误EXC_BAD_访问;表+;标签栏

使用sqlite3+;时,XCode错误EXC_BAD_访问;表+;标签栏,xcode,uitableview,uitabbarcontroller,xcode4.2,exc-bad-access,Xcode,Uitableview,Uitabbarcontroller,Xcode4.2,Exc Bad Access,我有一个类ClsDatabase,它被调用来保存/检索数据。 还有两个视图。第二个视图包含一个表,该表将根据检索到的ClsDataBase显示信息。选项卡栏控制这两个视图 它可以在显示第一个视图的情况下进行初始加载。但是,当我选择第二个视图时,它会在main.m处停止 return UIApplicationMain(argc, argv, nil, NSStringFromClass([TestTabBarAppDelegate class])); 带有错误消息:EXC\u访问错误 我尝试创

我有一个类ClsDatabase,它被调用来保存/检索数据。 还有两个视图。第二个视图包含一个表,该表将根据检索到的ClsDataBase显示信息。选项卡栏控制这两个视图

它可以在显示第一个视图的情况下进行初始加载。但是,当我选择第二个视图时,它会在main.m处停止

return UIApplicationMain(argc, argv, nil, NSStringFromClass([TestTabBarAppDelegate class]));
带有错误消息:EXC\u访问错误

我尝试创建另一个项目,但没有ClsDatabase,只在表中打印一些Dummy值,它就工作了。不确定是否是因为类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;
}
(第二视图)


你在代码中做了很多应该用IB和故事板来完成的事情


indexath.row
0
arrder
为空且尚未创建单元格时,
cellforrowatinexpath
中的逻辑将在第一行失败。这就解释了EXC_BAD_访问错误

当我尝试使用NSZombieEnabled跟踪此类错误时,当我单击第二个选项卡时,应用程序在僵尸消息之前退出。你发布的代码太多了。尽量减少,只显示你怀疑可能包含问题的部分。是的。已经降到最低了…很抱歉。
#import <UIKit/UIKit.h>

#import "ClsDatabase.h"

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

@end
#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;
    }
}