当我在表视图上选择一个单元格时,我的应用程序崩溃,但我无法找到代码中崩溃的位置 [英] My app crashes when I select a cell on a table view but I cant find where in the code it crashes

查看:162
本文介绍了当我在表视图上选择一个单元格时,我的应用程序崩溃,但我无法找到代码中崩溃的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从表格视图切换到详细视图。当我点击单元格时它会崩溃。我已经使用了休息来尝试找到它崩溃的代码,但我找不到特定的行。当从表视图到详细视图执行segue时,它会崩溃。我想将一些变量传递给详细视图但我首先需要让它切换到详细视图。我正在使用故事板fyi。任何帮助将不胜感激。

I am trying to switch from a table view to a detail view. When I click on the cell it crashes. I have used breaks to try and find where in the code it crashes but I cant find a specific line. It crashes when the segue is performed from the table view to the detail view. I would like to pass some variables to the detail view but I first need to get it to switch to the detail view. I am using storyboard fyi. Any help would be appreciated.

更新:崩溃日志如下

arg c = (int) 1
arg v = (char **) 0x2fd63cdc

这是崩溃所在的行

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

更新2

最后一节当我逐步执行代码时崩溃之前的代码就是为segue函数做准备。在那里的最后一行代码之后它崩溃并转到上面一行。

The last section of code before it crashes when I am stepping through the code is the prepare for segue function. After the last line of code in there it crashes and goes to the line above.

更新3

我意识到控制台已被隐藏,因此这是控制台中显示的错误。我的两个准备segue的nslog都被调用了。

I realized the console was hidden so this is the error that shows up in the console. Both of my nslogs in prepare for segue were called.

Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<DetailViewController 0x1e098bd0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key name.'
*** First throw call stack:
(0x3a1e63e7 0x39072963 0x3a1e60d5 0x3a418fe9 0x3a414d53 0x3a16c8a5 0x39665d7d 0x396655ff 0x3955e039 0x394e8421 0x3953d1b7 0x3953d0fd 0x3953cfe1 0x3953cf0d 0x3953c659 0x3953c541 0x3952ab33 0x3952a7d3 0x3958b2ad 0x3960dca1 0x3a4b9e67 0x3a1bb857 0x3a1bb503 0x3a1ba177 0x3a12d23d 0x3a12d0c9 0x3746633b 0x3951d291 0x69a9 0x3a91eb20)
libc++abi.dylib: terminate called throwing an exception

RootViewController.m

RootViewController.m

#import "RootViewController.h"
#import "DetailViewController.h"



@implementation RootViewController

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];

    //Initialize the array.
    listOfItems = [[NSMutableArray alloc] init];

    //Add items
    [listOfItems addObject:@"Jane"];
    [listOfItems addObject:@"Johnny"];
    [listOfItems addObject:@"Deanne"];
    [listOfItems addObject:@"John"];
    [listOfItems addObject:@"Susan"];

    //Set the title
    self.navigationItem.title = @"Countries";
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [listOfItems count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"MyCell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    // Set up the cell...
    NSString *cellValue = [listOfItems objectAtIndex:indexPath.row];
    cell.textLabel.text = cellValue;


    return cell;
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    DetailViewController *DVC = [[DetailViewController alloc]init];
    DVC = [segue destinationViewController];
    NSIndexPath *path = [self.tableView indexPathForSelectedRow];
    NSString *name = [listOfItems objectAtIndex:path.row];
    DVC.name1.text = name;
}

RootViewController.h

RootViewController.h

#import <UIKit/UIKit.h>

@interface RootViewController : UITableViewController <UITableViewDataSource,UITableViewDelegate> {

    NSMutableArray *listOfItems;
    IBOutlet NSMutableArray *detailListOfItems;
}
@end

DetailViewController.m

DetailViewController.m

#import "DetailViewController.h"



@implementation DetailViewController
@synthesize selectedCountry;
@synthesize name1;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}


- (void)viewDidLoad
{
    [super viewDidLoad];


    //Set the title of the navigation bar
    //self.navigationItem.title = name1.text;

}

DetailViewController.h

DetailViewController.h

#import <UIKit/UIKit.h>

@interface DetailViewController : UIViewController


@property (nonatomic,strong) IBOutlet UILabel *name1;
@property (nonatomic, retain) NSString *selectedCountry;
@end


推荐答案

添加例外断点。 ...

Add an exception breakpoint....

以下是顶部的标签:

您需要选择第二个最后一个断点图标。按下并查看底部的添加图标:

You need to select the 2nd last breakpoint icon one. Press that and look at the bottom for the add icon:

然后按添加并创建例外断点并将其修改为以下设置:

Then press add and create an exception breakpoint and modify it to these settings:

继承人你的断点异常!

然后运行你的应用程序,它应该崩溃你的线路崩溃。您可能会看到一些崩溃日志,并且可能需要将方案更改为GDB

Then run your app and it should crash on your line where it crashes. You may see some crash log, and its possible you have to change the scheme to GDB

更新

是否存在任何类型的崩溃日志或堆栈跟踪?另外,尝试将方案更改为GDB ......以下是:

Is there any sort of crash log or stack trace? Also, try changing the scheme to GDB... heres how:

切换到GDB通常会修复此问题。如果您已经使用GDB,请切换到LLDB,看看会发生什么!

Switching to GDB usually fixes this. If you are already using GDB, switch to LLDB and see what happens!

注意:正如您发布的那样,

Note: as you posted,


arg c =(int)1

arg c = (int) 1

arg v =(char **)0x2fd63cdc

arg v = (char **) 0x2fd63cdc

您的崩溃日志......

Is not your crash log...

更新

如果这仍然不起作用,你应该放置断点和 NSLog()到处调试并找出你的崩溃代码的位置!

If this still does not work you should put breakpoints and NSLog()'s all over the place to debug and find out your bad crashy code's position!

更新

看起来我们显然无法找到崩溃的位置,但我可能会对崩溃的原因和原因有一个微妙的线索。它与您的表视图和 listOfItems 相关。通常,表视图会重新加载其数据并在之前或同时调用其委托和数据源方法 viewDidLoad 代码被调用。因此,将 listOfItems 的初始化和添加对象转移到 viewWillAppear ,看看会发生什么。

Look we obviously can't find out where it is crashing, but I might have a subtle clue on where the thing is crashing and why. Its related to your table view and listOfItems. Usually a table view reloads its data and calls its delegate and data source methods just before or simultaneously viewDidLoad code gets called. So transfer the initialization and adding of objects of listOfItems to viewWillAppear and see what happens.

更新

检查故事板中的所有商店和在 DetailViewController 中,确保它们没有连接到任何不存在的东西

Check all your outlets in your storyboard and in DetailViewController and make sure they are not connected to anything that doesn't exist anymore

这篇关于当我在表视图上选择一个单元格时,我的应用程序崩溃,但我无法找到代码中崩溃的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆