objective-c - Sigbart 错误 : 'NSInvalidArgumentException'
<p><p>在过去的一天里,我刚刚破坏了我的 rootViewController。我现在遇到了这个错误,我不知道去哪里修复它。 </p>
<p>任何有关如何修复甚至更好的帮助,帮助我破译错误输出,以便我自己做。 </p>
<pre><code>2011-10-24 08:56:29.746 DiningLog -: unrecognized selector sent to instance 0x595b150
2011-10-24 08:56:29.749 DiningLog *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-: unrecognized selector sent to instance 0x595b150'
*** Call stack at first throw:
(
0 CoreFoundation 0x00fa25a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x010f6313 objc_exception_throw + 44
2 CoreFoundation 0x00fa40bb - + 187
3 CoreFoundation 0x00f13966 ___forwarding___ + 966
4 CoreFoundation 0x00f13522 _CF_forwarding_prep_0 + 50
5 UIKit 0x00330bd5 - + 695
6 UIKit 0x003264cc - + 75
7 UIKit 0x0033b8cc - + 1561
8 UIKit 0x0033390c - + 242
9 QuartzCore 0x01f42a5a - + 181
10QuartzCore 0x01f44ddc CALayerLayoutIfNeeded + 220
11QuartzCore 0x01eea0b4 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 310
12QuartzCore 0x01eeb294 _ZN2CA11Transaction6commitEv + 292
13UIKit 0x002bd9c9 - + 39
14UIKit 0x002bde83 - + 690
15UIKit 0x002c8617 - + 1533
16UIKit 0x002c0abf - + 71
17UIKit 0x002c5f2e _UIApplicationHandleEvent + 7576
18GraphicsServices 0x018fa992 PurpleEventCallback + 1550
19CoreFoundation 0x00f83944 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
20CoreFoundation 0x00ee3cf7 __CFRunLoopDoSource1 + 215
21CoreFoundation 0x00ee0f83 __CFRunLoopRun + 979
22CoreFoundation 0x00ee0840 CFRunLoopRunSpecific + 208
23CoreFoundation 0x00ee0761 CFRunLoopRunInMode + 97
24UIKit 0x002bd7d2 - + 623
25UIKit 0x002c9c93 UIApplicationMain + 1160
26DiningLog 0x0000213c main + 102
27DiningLog 0x000020cd start + 53
)
terminate called after throwing an instance of 'NSException'
Current language:auto; currently objective-c
(gdb)
</code></pre>
<p>这里是请求的代码:</p>
<pre><code>//
//RootViewController.m
//DiningLog
//
//Created by Eric Rea on 3/3/11.
//Copyright 2011 Avid. All rights reserved.
//
#import "RootViewController.h"
#import "ModalView.h"
@interface RootViewController ()
- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath;
@end
@implementation RootViewController
@synthesize fetchedResultsController=fetchedResultsController_, managedObjectContext=managedObjectContext_;
@synthesize plistArray, excersizeArray;
#pragma mark -
#pragma mark View lifecycle
- (void)viewDidLoad {
;
// Set up the edit and add buttons.
self.navigationItem.leftBarButtonItem = self.editButtonItem;
UIBarButtonItem *addButton = [ initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(insertNewObject)];
self.navigationItem.rightBarButtonItem = addButton;
;
// get paths from root direcory
NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
// get documents path
NSString *documentsPath = ;
// get the path to our Data/plist file
NSString *plistPath = ;
// check to see if Data.plist exists in documents
if (![ fileExistsAtPath:plistPath])
{
// if not in documents, get property list from main bundle
plistPath = [ pathForResource:@"Excersizes" ofType:@"plist"];
}
// read property list into memory as an NSData object
NSData *plistXML = [ contentsAtPath:plistPath];
NSString *errorDesc = nil;
NSPropertyListFormat format;
// convert static property list into dictionary object
NSDictionary *temp = (NSDictionary *);
if (!temp)
{
NSLog(@"Error reading plist: %@, format: %d", errorDesc, format);
}
// assign values
self.plistArray = ];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return ;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
/* create your cell here */
excersizeArray = ];
/* fill the cell with the info in my object */
return ;
}
// Implement viewWillAppear: to do additional setup before the view is presented.
- (void)viewWillAppear:(BOOL)animated {
;
}
/*
- (void)viewDidAppear:(BOOL)animated {
;
}
*/
/*
- (void)viewWillDisappear:(BOOL)animated {
;
}
*/
/*
- (void)viewDidDisappear:(BOOL)animated {
;
}
*/
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations.
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath {
NSManagedObject *managedObject = ;
cell.textLabel.text = [ description];
}
#pragma mark -
#pragma mark Add a new object
- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
// Prevent new objects being added when in editing mode.
;
self.navigationItem.rightBarButtonItem.enabled = !editing;
}
#pragma mark -
#pragma mark Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 20;
}
/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
// Return NO if you do not want the specified item to be editable.
return YES;
}
*/
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the managed object for the given index path
NSManagedObjectContext *context = ;
];
// Save the context.
NSError *error = nil;
if (!) {
/*
Replace this implementation with code to handle the error appropriately.
abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. If it is not possible to recover from the error, display an alert panel that instructs the user to quit the application by pressing the Home button.
*/
NSLog(@"Unresolved error %@, %@", error, );
abort();
}
}
}
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
// The table view should not be re-orderable.
return NO;
}
#pragma mark -
#pragma mark Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Navigation logic may go here -- for example, create and push another view controller.
/*
<#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
NSManagedObject *selectedObject = [ objectAtIndexPath:indexPath];
// ...
// Pass the selected object to the new view controller.
;
;
*/
}
#pragma mark -
#pragma mark Fetched results controller
- (NSFetchedResultsController *)fetchedResultsController {
if (fetchedResultsController_ != nil) {
return fetchedResultsController_;
}
/*
Set up the fetched results controller.
*/
// Create the fetch request for the entity.
NSFetchRequest *fetchRequest = [ init];
// Edit the entity name as appropriate.
NSEntityDescription *entity = ;
;
// Set the batch size to a suitable number.
;
// Edit the sort key as appropriate.
NSSortDescriptor *sortDescriptor = [ initWithKey:@"Excersizes" ascending:NO];
NSArray *sortDescriptors = [ initWithObjects:sortDescriptor, nil];
;
// Edit the section name key path and cache name if appropriate.
// nil for section name key path means "no sections".
NSFetchedResultsController *aFetchedResultsController = [ initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:nil cacheName:@"Root"];
aFetchedResultsController.delegate = self;
self.fetchedResultsController = aFetchedResultsController;
;
;
;
;
NSError *error = nil;
if (!) {
/*
Replace this implementation with code to handle the error appropriately.
abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. If it is not possible to recover from the error, display an alert panel that instructs the user to quit the application by pressing the Home button.
*/
NSLog(@"Unresolved error %@, %@", error, );
abort();
}
return fetchedResultsController_;
}
#pragma mark -
#pragma mark Fetched results controller delegate
- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller {
;
}
- (void)controller:(NSFetchedResultsController *)controller didChangeSection:(id <NSFetchedResultsSectionInfo>)sectionInfo
atIndex:(NSUInteger)sectionIndex forChangeType:(NSFetchedResultsChangeType)type {
switch(type) {
case NSFetchedResultsChangeInsert:
withRowAnimation:UITableViewRowAnimationFade];
break;
case NSFetchedResultsChangeDelete:
withRowAnimation:UITableViewRowAnimationFade];
break;
}
}
- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject
atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type
newIndexPath:(NSIndexPath *)newIndexPath {
UITableView *tableView = self.tableView;
switch(type) {
case NSFetchedResultsChangeInsert:
withRowAnimation:UITableViewRowAnimationFade];
break;
case NSFetchedResultsChangeDelete:
withRowAnimation:UITableViewRowAnimationFade];
break;
case NSFetchedResultsChangeUpdate:
atIndexPath:indexPath];
break;
case NSFetchedResultsChangeMove:
withRowAnimation:UITableViewRowAnimationFade];
withRowAnimation:UITableViewRowAnimationFade];
break;
}
}
- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller {
;
}
/*
// Implementing the above methods to update the table view in response to individual changes may have performance implications if a large number of changes are made simultaneously. If this proves to be an issue, you can instead just implement controllerDidChangeContent: which notifies the delegate that all section and object changes have been processed.
- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller {
// In the simplest, most efficient, case, reload the table view.
;
}
*/
#pragma mark -
#pragma mark Memory management
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
;
// Relinquish ownership any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Relinquish ownership of anything that can be recreated in viewDidLoad or on demand.
// For example: self.myOutlet = nil;
}
- (void)dealloc {
;
;
;
}
@end
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>我看到您返回的是数组而不是单元格,您可以将代码更改为以下内容:</p>
<pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = ;
if (cell == nil) {
cell = [[ initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
// Set up the cell...
cell.text = @"Value";
return cell;
}
</code></pre></p>
<p style="font-size: 20px;">关于objective-c - Sigbart 错误 :'NSInvalidArgumentException' ,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/7877641/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/7877641/
</a>
</p>
页:
[1]