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

时间:2014-04-04 21:08:06

标签: ios objective-c xcode

我真的很喜欢iOS开发(以及一般的编程),如果你能解释我什么时候出现SIGABRT错误,我会很感激,我该怎么办才能解决?

我从一个表视图控制器到另一个视图控制器做了一个segue,当我点击一个单元格来预先形成segue时,我得到了这个:

这是整个控制台:

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

2 个答案:

答案 0 :(得分:2)

控制台输出的前两行告诉你一切......

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'

看起来您在content上调用了UITableviewCell方法,但此方法未在任何地方声明。尝试检查您的代码(查看内部为UITableView的控制器)并查找调用[UITableViewCell content]方法的行。


他得到了......在你的NMCreateNotesViewController中,没有任何contet方法,但你是用prepareForSegue:sender:方法调用它。

答案 1 :(得分:2)

问题在于您如何访问要传递的记事,

- (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设置目标视图控制器中textField的值。你不能这样做,因为控制器的视图还没有被加载,所以它的出口将是零。相反,在NMCreateNotesViewController中创建一个字符串属性(我称之为passInString),并使用它在viewDidLoad方法中设置文本字段的文本。

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