gpt4 book ai didi

ios - 当我收到 SIGABRT 错误时,如何了解我的错误在哪里?

转载 作者:行者123 更新时间:2023-12-01 18:14:59 25 4
gpt4 key购买 nike

我对 iOS 开发人员(以及一般编程)真的很陌生,如果您能解释一下我收到 SIGABRT 错误时,我应该研究什么来修复?

我从一个表格 View Controller 到另一个 View Controller 进行了转场,当我点击一个单元格来执行转场时,我得到了这个:

这是整个控制台:

2014-04-05 00:12:21.832 Robonote[20893:70b] -[UITableViewCell content]: unrecognized selector sent to instance 0x8acb5a0
2014-04-05 00:12:21.874 Robonote[20893:70b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITableViewCell content]: unrecognized selector sent to instance 0x8acb5a0'
*** First throw call stack:
(
0 CoreFoundation 0x0173d5e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x014c08b6 objc_exception_throw + 44
2 CoreFoundation 0x017da903 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x0172d90b ___forwarding___ + 1019
4 CoreFoundation 0x0172d4ee _CF_forwarding_prep_0 + 14
5 Robonote 0x00003d3f -[NMNotesListViewController prepareForSegue:sender:] + 287
6 UIKit 0x0076306c -[UIStoryboardSegueTemplate _perform:] + 156
7 UIKit 0x007630f9 -[UIStoryboardSegueTemplate perform:] + 115
8 UIKit 0x00310775 -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] + 1453
9 UIKit 0x00310924 -[UITableView _userSelectRowAtPendingSelectionIndexPath:] + 279
10 UIKit 0x00314908 __38-[UITableView touchesEnded:withEvent:]_block_invoke + 43
11 UIKit 0x0024b183 ___afterCACommitHandler_block_invoke + 15
12 UIKit 0x0024b12e _applyBlockToCFArrayCopiedToStack + 403
13 UIKit 0x0024af5a _afterCACommitHandler + 532
14 CoreFoundation 0x017054ce __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
15 CoreFoundation 0x0170541f __CFRunLoopDoObservers + 399
16 CoreFoundation 0x016e3344 __CFRunLoopRun + 1076
17 CoreFoundation 0x016e2ac3 CFRunLoopRunSpecific + 467
18 CoreFoundation 0x016e28db CFRunLoopRunInMode + 123
19 GraphicsServices 0x036e29e2 GSEventRunModal + 192
20 GraphicsServices 0x036e2809 GSEventRun + 104
21 UIKit 0x0022ed3b UIApplicationMain + 1225
22 Robonote 0x0000357d main + 141
23 libdyld.dylib 0x01d7b701 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)

这是 NMNotesListViewController.m :
    import "NMNotesListViewController.h"
#import "NMCreateNotesViewController.h"

@interface NMNotesListViewController ()

@property (strong, nonatomic) NSMutableArray *notes;

@end

@implementation NMNotesListViewController



- (IBAction) unwindToList: (UIStoryboardSegue *) segue
{

NMCreateNotesViewController *source = [segue sourceViewController];
NMNote *note = source.note;

if (note != nil) {
[self.notes addObject:note];
[self.tableView reloadData];
}

}

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

- (void)viewDidLoad
{
[super viewDidLoad];

self.notes = [[NSMutableArray alloc] init];

// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;

// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

- (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 the number of rows in the section.
return [self.notes count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"NotesPrototypeCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

// Configure the cell...


NMNote *note = [self.notes objectAtIndex:indexPath.row];
cell.textLabel.text = note.content;


return cell;
}


- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(UITableViewCell *)sender

{
if ([[segue identifier] isEqualToString:@"noteSegue"]) {
NMCreateNotesViewController *destination = [segue destinationViewController];
NSInteger indx = [self.tableView indexPathForCell:sender].row;
NMNote *note = self.notes[indx];
destination.passedInString = note.content;
}
}


//#pragma mark - delegate
//
//- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
//{
//
//}

@end

这是 NMCreateNotesViewController.m :
 #import "NMCreateNotesViewController.h"
#import "NMNotesListViewController.h"


@interface NMCreateNotesViewController () <UITextViewDelegate>

@property (weak, nonatomic) IBOutlet UIBarButtonItem *saveButton;



@end



@implementation NMCreateNotesViewController


- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];

// listen for keyboard hide/show notifications so we can properly adjust the table's height
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillHide:)
name:UIKeyboardWillHideNotification
object:nil];
}


#pragma mark - Notifications


- (void)adjustViewForKeyboardReveal:(BOOL)showKeyboard notificationInfo:(NSDictionary *)notificationInfo
{
// the keyboard is showing so ƒ the table's height
CGRect keyboardRect = [[notificationInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
NSTimeInterval animationDuration =
[[notificationInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
CGRect frame = self.textField.frame;

// the keyboard rect's width and height are reversed in landscape
NSInteger adjustDelta = UIInterfaceOrientationIsPortrait(self.interfaceOrientation) ? CGRectGetHeight(keyboardRect) : CGRectGetWidth(keyboardRect);

if (showKeyboard)
frame.size.height -= adjustDelta;
else
frame.size.height += adjustDelta;

[UIView beginAnimations:@"ResizeForKeyboard" context:nil];
[UIView setAnimationDuration:animationDuration];
self.textField.frame = frame;
[UIView commitAnimations];
}



- (void)keyboardWillShow:(NSNotification *)aNotification
{
[self adjustViewForKeyboardReveal:YES notificationInfo:[aNotification userInfo]];
}



- (void)keyboardWillHide:(NSNotification *)aNotification
{
[self adjustViewForKeyboardReveal:NO notificationInfo:[aNotification userInfo]];
}



- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if (sender != self.saveButton) return;
if (self.textField.text.length > 0) {
self.note = [[NMNote alloc] init];
self.note.content = self.textField.text;

}
}



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



- (void)viewDidLoad
{
[super viewDidLoad];
if (self.passedInString != nil) {
self.textField.text = self.passedInString;
}
// Do any additional setup after loading the view.
}



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

@end

最佳答案

问题在于您如何访问要传递的注释,

- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender

{
if ([[segue identifier] isEqualToString:@"noteSegue"]) {
NMCreateNotesViewController *destination = [segue destinationViewController];
NMNote *note = (NMNote*) sender;
destination.textField.text = note.content;
}
}

这应该是,
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(UITableViewCell *)sender

{
if ([[segue identifier] isEqualToString:@"noteSegue"]) {
NMCreateNotesViewController *destination = [segue destinationViewController];
NSInteger indx = [self.tableView indexPathForCell:sender].row;
NMNote *note = self.notes[indx];
destination.passedInString = note.content;
}
}

您遇到的另一个问题是尝试通过 prepareForSegue 在目标 View Controller 中设置 textField 的值。您不能这样做,因为该 Controller 的 View 尚未加载,因此它的导出将为零。相反,在 NMCreateNotesViewController 中创建一个字符串属性(我称之为 passInString),并使用它在 viewDidLoad 方法中设置文本字段的文本。

如果您的 segue 从单元连接到下一个 Controller ,那么您不应该在代码中调用 performSegueWithIdentifier:。实际上,您根本不需要实现 didSelectRowAtIndexPath:。

关于ios - 当我收到 SIGABRT 错误时,如何了解我的错误在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22873028/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com