得到SIGABRT错误

时间:2013-10-24 22:49:09

标签: ios uitableview sigabrt

在main.m中收到SIGABRT错误:

#import <UIKit/UIKit.h>

#import "AppDelegate.h"

int main(int argc, char * argv[])
{
    @autoreleasepool {
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); // SIGABRT error
    }
}

我在控制台中得到这个,但无法理解:

2013-10-24 15:21:30.278 Blog_Reader[45888:a0b] -[__NSDictionaryI length]: unrecognized selector sent to instance 0xb779360
2013-10-24 15:21:30.293 Blog_Reader[45888:a0b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSDictionaryI length]: unrecognized selector sent to instance 0xb779360'
*** First throw call stack:
(
    0   CoreFoundation                      0x017345e4 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x014b78b6 objc_exception_throw + 44
    2   CoreFoundation                      0x017d1903 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
    3   CoreFoundation                      0x0172490b ___forwarding___ + 1019
    4   CoreFoundation                      0x017244ee _CF_forwarding_prep_0 + 14
    5   Foundation                          0x010fcb2d -[NSConcreteMutableAttributedString replaceCharactersInRange:withString:] + 39
    6   Foundation                          0x010fd79a -[NSConcreteMutableAttributedString initWithString:attributes:] + 293
    7   UIKit                               0x003d7116 -[UILabel _setText:] + 97
    8   UIKit                               0x003d72d4 -[UILabel setText:] + 40
    9   Blog_Reader                         0x00002c3d -[TableViewController tableView:cellForRowAtIndexPath:] + 301
    10  UIKit                               0x00318d2f -[UITableView _createPreparedCellForGlobalRow:withIndexPath:] + 412
    11  UIKit                               0x00318e03 -[UITableView _createPreparedCellForGlobalRow:] + 69
    12  UIKit                               0x002fd124 -[UITableView _updateVisibleCellsNow:] + 2378
    13  UIKit                               0x003105a5 -[UITableView layoutSubviews] + 213
    14  UIKit                               0x00294dd7 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355
    15  libobjc.A.dylib                     0x014c981f -[NSObject performSelector:withObject:] + 70
    16  QuartzCore                          0x03aee72a -[CALayer layoutSublayers] + 148
    17  QuartzCore                          0x03ae2514 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
    18  QuartzCore                          0x03aee675 -[CALayer layoutIfNeeded] + 160
    19  UIKit                               0x0034fca3 -[UIViewController window:setupWithInterfaceOrientation:] + 304
    20  UIKit                               0x0026ed27 -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:isRotating:] + 5212
    21  UIKit                               0x0026d8c6 -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:] + 82
    22  UIKit                               0x0026d798 -[UIWindow _setRotatableViewOrientation:updateStatusBar:duration:force:] + 117
    23  UIKit                               0x0026d820 -[UIWindow _setRotatableViewOrientation:duration:force:] + 67
    24  UIKit                               0x0026c8ba __57-[UIWindow _updateToInterfaceOrientation:duration:force:]_block_invoke + 120
    25  UIKit                               0x0026c81c -[UIWindow _updateToInterfaceOrientation:duration:force:] + 400
    26  UIKit                               0x0026d573 -[UIWindow setAutorotates:forceUpdateInterfaceOrientation:] + 870
    27  UIKit                               0x00270b66 -[UIWindow setDelegate:] + 449
    28  UIKit                               0x00341dc7 -[UIViewController _tryBecomeRootViewControllerInWindow:] + 180
    29  UIKit                               0x002667cc -[UIWindow addRootViewControllerViewIfPossible] + 609
    30  UIKit                               0x00266947 -[UIWindow _setHidden:forced:] + 312
    31  UIKit                               0x00266bdd -[UIWindow _orderFrontWithoutMakingKey] + 49
    32  UIKit                               0x0027144a -[UIWindow makeKeyAndVisible] + 65
    33  Blog_Reader                         0x000023bb -[AppDelegate application:didFinishLaunchingWithOptions:] + 267
    34  UIKit                               0x00223f65 -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 309
    35  UIKit                               0x002247a5 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1536
    36  UIKit                               0x00228fb8 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 824
    37  UIKit                               0x0023d42c -[UIApplication handleEvent:withNewEvent:] + 3447
    38  UIKit                               0x0023d999 -[UIApplication sendEvent:] + 85
    39  UIKit                               0x0022ac35 _UIApplicationHandleEvent + 736
    40  GraphicsServices                    0x036872eb _PurpleEventCallback + 776
    41  GraphicsServices                    0x03686df6 PurpleEventCallback + 46
    42  CoreFoundation                      0x016afdd5 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 53
    43  CoreFoundation                      0x016afb0b __CFRunLoopDoSource1 + 523
    44  CoreFoundation                      0x016da7ec __CFRunLoopRun + 2156
    45  CoreFoundation                      0x016d9b33 CFRunLoopRunSpecific + 467
    46  CoreFoundation                      0x016d994b CFRunLoopRunInMode + 123
    47  UIKit                               0x002286ed -[UIApplication _run] + 840
    48  UIKit                               0x0022a94b UIApplicationMain + 1225
    49  Blog_Reader                         0x00002e2d main + 141
    50  libdyld.dylib                       0x01d70725 start + 0
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

这是TableViewController.m文件:

@implementation TableViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

    NSDictionary *blogPost1 = [NSDictionary dictionaryWithObjectsAndKeys:@"The Missing Widget in Android", @"title", @"Ben Jakuben", @"author", nil];

     NSDictionary *blogPost2 = [NSDictionary dictionaryWithObjectsAndKeys:@"Getting Started with iOS Development", @"title", @"Amit Bijlani", @"author", nil];

     NSDictionary *blogPost3 = [NSDictionary dictionaryWithObjectsAndKeys:@"An Interview with Shay Howe", @"title", @"Joe Villanueva", @"author", nil];


    self.blogPosts = [NSArray arrayWithObjects:blogPost1, blogPost2, blogPost3, nil];

}

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

    // Configure the cell...
    cell.textLabel.text = [self.blogPosts objectAtIndex:indexPath.row];

    return cell;
}

@end

1 个答案:

答案 0 :(得分:2)

您要将NSDictionary个实例存储在self.blogPosts中,然后存储在

cell.textLabel.text = [self.blogPosts objectAtIndex:indexPath.row];

您要将其中一个分配给text,其中需要NSString。编译器没有捕获它,因为objectAtIndex:返回类型为id的对象,它可能是任何东西。

可能的修复(但实际上取决于你需要的)可能是

cell.textLabel.text = self.blogPosts[indexPath.row][@"title"];