简体   繁体   English

当我在表格视图中选择一个单元格时,我的应用程序崩溃了,但是我找不到在代码崩溃的地方

[英]My app crashes when I select a cell on a table view but I cant find where in the code it crashes

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. 从表格视图到详细视图执行segue时,它会崩溃。 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. 我正在使用情节提要fyi。 Any help would be appreciated. 任何帮助,将不胜感激。

UPDATE: The crash log is as follows 更新:崩溃日志如下

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

This is the line the crash is on 这是崩溃所在的行

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

UPDATE 2 更新2

The last section of code before it crashes when I am stepping through the code is the prepare for segue function. 当我单步执行代码时,代码崩溃前的最后一部分是segue函数的准备工作。 After the last line of code in there it crashes and goes to the line above. 那里的最后一行代码崩溃后,转到上面的行。

UPDATE 3 更新3

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. 我的两个准备登录的nslog都被调用了。

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.... 添加异常断点...。

Here is the tab at the top: 这是顶部的标签:

在此处输入图片说明

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: 然后按添加并创建一个异常断点,并将其修改为以下设置:

在此处输入图片说明

And heres your breakpoint exception! 这是您的断点异常!

在此处输入图片说明

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


Update 更新

Is there any sort of crash log or stack trace? 是否有任何崩溃日志或堆栈跟踪? Also, try changing the scheme to GDB... heres how: 另外,尝试将方案更改为GDB ...这是如何做的:

在此处输入图片说明

在此处输入图片说明

在此处输入图片说明

Switching to GDB usually fixes this. 切换到GDB通常可以解决此问题。 If you are already using GDB, switch to LLDB and see what happens! 如果您已经在使用GDB,请切换到LLDB,然后看看会发生什么!

Note: as you posted, 注意:如您所张贴,

arg c = (int) 1 arg c =(整数)1

arg v = (char **) 0x2fd63cdc arg v =(字符**)0x2fd63cdc

Is not your crash log... 不是您的当机记录...


Update 更新

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! 如果仍然无法解决问题,则应在各处放置断点和NSLog()进行调试,以找出不良的崩溃代码位置!


Update 更新

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 . 它与您的表视图和listOfItems Usually a table view reloads its data and calls its delegate and data source methods just before or simultaneously viewDidLoad code gets called. 通常,表视图会在调用viewDidLoad代码之前或同时调用表视图,以重新加载其数据并调用其委托和数据源方法。 So transfer the initialization and adding of objects of listOfItems to viewWillAppear and see what happens. 因此,将listOfItems对象的初始化和添加转移到viewWillAppear ,看看会发生什么。


Update 更新

Check all your outlets in your storyboard and in DetailViewController and make sure they are not connected to anything that doesn't exist anymore 检查情节DetailViewControllerDetailViewController所有出口,并确保它们未连接到不再存在的任何东西

继承人的解决方案:检查您的单元标识符的名称,并将此标识符应用于您的segue。每个Segue都有一个标识符。.default为空。视图控制器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM