Joh*_*Cox 0 uitableview tableview ios ios6
我正在尝试从表格视图切换到详细视图.当我点击单元格时它会崩溃.我已经使用了休息来尝试找到它崩溃的代码,但我找不到特定的行.当从表视图到详细视图执行segue时,它会崩溃.我想将一些变量传递给详细视图但我首先需要让它切换到详细视图.我正在使用故事板fyi.任何帮助,将不胜感激.
更新:崩溃日志如下
arg c = (int) 1
arg v = (char **) 0x2fd63cdc
Run Code Online (Sandbox Code Playgroud)
这就是崩溃的路线
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
Run Code Online (Sandbox Code Playgroud)
更新2
当我逐步完成代码时崩溃之前的最后一段代码就是为segue函数做准备.在那里的最后一行代码之后它崩溃并转到上面的一行.
更新3
我意识到控制台已被隐藏,因此这是控制台中显示的错误.我的两个准备segue的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
Run Code Online (Sandbox Code Playgroud)
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;
}
Run Code Online (Sandbox Code Playgroud)
RootViewController.h
#import <UIKit/UIKit.h>
@interface RootViewController : UITableViewController <UITableViewDataSource,UITableViewDelegate> {
NSMutableArray *listOfItems;
IBOutlet NSMutableArray *detailListOfItems;
}
@end
Run Code Online (Sandbox Code Playgroud)
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;
}
Run Code Online (Sandbox Code Playgroud)
DetailViewController.h
#import <UIKit/UIKit.h>
@interface DetailViewController : UIViewController
@property (nonatomic,strong) IBOutlet UILabel *name1;
@property (nonatomic, retain) NSString *selectedCountry;
@end
Run Code Online (Sandbox Code Playgroud)
添加异常断点....
这是顶部的标签:

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

然后按添加并创建一个异常断点并将其修改为以下设置:

继续你的断点异常!

然后运行你的应用程序,它应该崩溃你的线崩溃.您可能会看到一些崩溃日志,并且可能需要将方案更改为GDB
更新
是否有任何类型的崩溃日志或堆栈跟踪?另外,尝试将方案更改为GDB ...继承人如何:



切换到GDB通常可以解决这个问题.如果您已经在使用GDB,请切换到LLDB,看看会发生什么!
注意:正如您发布的那样,
arg c =(int)1
arg v =(char**)0x2fd63cdc
是不是你的崩溃日志...
更新
如果这仍然不起作用你应该把断点和NSLog()所有地方调试并找出你的坏崩溃代码的位置!
更新
看起来我们显然无法找到崩溃的位置,但我可能会对崩溃的原因和原因有一个微妙的线索.它与你的表视图和listOfItems.通常,表视图会重新加载其数据,并在调用viewDidLoad代码之前或同时调用其委托和数据源方法.所以转移初始化和添加的对象listOfItems来viewWillAppear看看会发生什么.
更新
检查故事板中的所有插座,DetailViewController并确保它们不再连接到任何不存在的 插座
| 归档时间: |
|
| 查看次数: |
1333 次 |
| 最近记录: |