2011-10-24 82 views
2

我剛在過去一天中毀壞了我的rootViewController。我現在得到這個錯誤,我不知道要在哪裏修復它。Sigbart錯誤:'NSInvalidArgumentException'

任何關於如何解決或者甚至更好的幫助都可以幫助我破譯錯誤輸出,所以我可以自己做。

2011-10-24 08:56:29.746 DiningLog[2955:207] -[NSCFString setTableViewStyle:]: unrecognized selector sent to instance 0x595b150 
2011-10-24 08:56:29.749 DiningLog[2955:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString setTableViewStyle:]: 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 -[NSObject(NSObject) doesNotRecognizeSelector:] + 187 
    3 CoreFoundation      0x00f13966 ___forwarding___ + 966 
    4 CoreFoundation      0x00f13522 _CF_forwarding_prep_0 + 50 
    5 UIKit        0x00330bd5 -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:withIndexPath:] + 695 
    6 UIKit        0x003264cc -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:] + 75 
    7 UIKit        0x0033b8cc -[UITableView(_UITableViewPrivate) _updateVisibleCellsNow:] + 1561 
    8 UIKit        0x0033390c -[UITableView layoutSubviews] + 242 
    9 QuartzCore       0x01f42a5a -[CALayer layoutSublayers] + 181 
    10 QuartzCore       0x01f44ddc CALayerLayoutIfNeeded + 220 
    11 QuartzCore       0x01eea0b4 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 310 
    12 QuartzCore       0x01eeb294 _ZN2CA11Transaction6commitEv + 292 
    13 UIKit        0x002bd9c9 -[UIApplication _reportAppLaunchFinished] + 39 
    14 UIKit        0x002bde83 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 690 
    15 UIKit        0x002c8617 -[UIApplication handleEvent:withNewEvent:] + 1533 
    16 UIKit        0x002c0abf -[UIApplication sendEvent:] + 71 
    17 UIKit        0x002c5f2e _UIApplicationHandleEvent + 7576 
    18 GraphicsServices     0x018fa992 PurpleEventCallback + 1550 
    19 CoreFoundation      0x00f83944 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52 
    20 CoreFoundation      0x00ee3cf7 __CFRunLoopDoSource1 + 215 
    21 CoreFoundation      0x00ee0f83 __CFRunLoopRun + 979 
    22 CoreFoundation      0x00ee0840 CFRunLoopRunSpecific + 208 
    23 CoreFoundation      0x00ee0761 CFRunLoopRunInMode + 97 
    24 UIKit        0x002bd7d2 -[UIApplication _run] + 623 
    25 UIKit        0x002c9c93 UIApplicationMain + 1160 
    26 DiningLog       0x0000213c main + 102 
    27 DiningLog       0x000020cd start + 53 
) 
terminate called after throwing an instance of 'NSException' 
Current language: auto; currently objective-c 
(gdb) 

下面是代碼的要求:

// 
// 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 { 
    [super viewDidLoad]; 

    // Set up the edit and add buttons. 
    self.navigationItem.leftBarButtonItem = self.editButtonItem; 

    UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(insertNewObject)]; 
    self.navigationItem.rightBarButtonItem = addButton; 
    [addButton release]; 

    // get paths from root direcory 
    NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES); 
    // get documents path 
    NSString *documentsPath = [paths objectAtIndex:0]; 
    // get the path to our Data/plist file 
    NSString *plistPath = [documentsPath stringByAppendingPathComponent:@"ExcersizeList.plist"]; 

    // check to see if Data.plist exists in documents 
    if (![[NSFileManager defaultManager] fileExistsAtPath:plistPath]) 
    { 
     // if not in documents, get property list from main bundle 
     plistPath = [[NSBundle mainBundle] pathForResource:@"Excersizes" ofType:@"plist"]; 
    } 

    // read property list into memory as an NSData object 
    NSData *plistXML = [[NSFileManager defaultManager] contentsAtPath:plistPath]; 
    NSString *errorDesc = nil; 
    NSPropertyListFormat format; 
    // convert static property list into dictionary object 
    NSDictionary *temp = (NSDictionary *)[NSPropertyListSerialization propertyListFromData:plistXML mutabilityOption:NSPropertyListMutableContainersAndLeaves format:&format errorDescription:&errorDesc]; 
    if (!temp) 
    { 
     NSLog(@"Error reading plist: %@, format: %d", errorDesc, format); 
    } 
    // assign values 
    self.plistArray = [NSMutableArray arrayWithArray:[temp objectForKey:@"Excersizes"]]; 

} 


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    return [self.plistArray count]; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    /* create your cell here */ 

    excersizeArray = [self.plistArray objectAtIndex:[indexPath row]]; 

             /* fill the cell with the info in my object */ 

    return [excersizeArray objectAtIndex:(NSUInteger)0]; 
             } 


// Implement viewWillAppear: to do additional setup before the view is presented. 
- (void)viewWillAppear:(BOOL)animated { 
    [super viewWillAppear:animated]; 
} 


/* 
- (void)viewDidAppear:(BOOL)animated { 
    [super viewDidAppear:animated]; 
} 
*/ 
/* 
- (void)viewWillDisappear:(BOOL)animated { 
    [super viewWillDisappear:animated]; 
} 
*/ 
/* 
- (void)viewDidDisappear:(BOOL)animated { 
    [super viewDidDisappear: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 = [self.fetchedResultsController objectAtIndexPath:indexPath]; 
    cell.textLabel.text = [[managedObject valueForKey:@"Excersizes"] 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. 
    [super setEditing:(BOOL)editing animated:(BOOL)animated]; 
    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 = [self.fetchedResultsController managedObjectContext]; 
     [context deleteObject:[self.fetchedResultsController objectAtIndexPath:indexPath]]; 

     // Save the context. 
     NSError *error = nil; 
     if (![context save:&error]) { 
      /* 
      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, [error userInfo]); 
      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 = [[self fetchedResultsController] objectAtIndexPath:indexPath]; 
    // ... 
    // Pass the selected object to the new view controller. 
    [self.navigationController pushViewController:detailViewController animated:YES]; 
    [detailViewController release]; 
    */ 
} 


#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 = [[NSFetchRequest alloc] init]; 
    // Edit the entity name as appropriate. 
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"Event" inManagedObjectContext:self.managedObjectContext]; 
    [fetchRequest setEntity:entity]; 

    // Set the batch size to a suitable number. 
    [fetchRequest setFetchBatchSize:20]; 

    // Edit the sort key as appropriate. 
    NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"Excersizes" ascending:NO]; 
    NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil]; 

    [fetchRequest setSortDescriptors:sortDescriptors]; 

    // Edit the section name key path and cache name if appropriate. 
    // nil for section name key path means "no sections". 
    NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:nil cacheName:@"Root"]; 
    aFetchedResultsController.delegate = self; 
    self.fetchedResultsController = aFetchedResultsController; 

    [aFetchedResultsController release]; 
    [fetchRequest release]; 
    [sortDescriptor release]; 
    [sortDescriptors release]; 

    NSError *error = nil; 
    if (![fetchedResultsController_ performFetch:&error]) { 
     /* 
     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, [error userInfo]); 
     abort(); 
    } 

    return fetchedResultsController_; 
}  


#pragma mark - 
#pragma mark Fetched results controller delegate 


- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller { 
    [self.tableView beginUpdates]; 
} 


- (void)controller:(NSFetchedResultsController *)controller didChangeSection:(id <NSFetchedResultsSectionInfo>)sectionInfo 
      atIndex:(NSUInteger)sectionIndex forChangeType:(NSFetchedResultsChangeType)type { 

    switch(type) { 
     case NSFetchedResultsChangeInsert: 
      [self.tableView insertSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationFade]; 
      break; 

     case NSFetchedResultsChangeDelete: 
      [self.tableView deleteSections:[NSIndexSet indexSetWithIndex:sectionIndex] 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: 
      [tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationFade]; 
      break; 

     case NSFetchedResultsChangeDelete: 
      [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; 
      break; 

     case NSFetchedResultsChangeUpdate: 
      [self configureCell:[tableView cellForRowAtIndexPath:indexPath] atIndexPath:indexPath]; 
      break; 

     case NSFetchedResultsChangeMove: 
      [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; 
      [tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath]withRowAnimation:UITableViewRowAnimationFade]; 
      break; 
    } 
} 


- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller { 
    [self.tableView endUpdates]; 
} 


/* 
// 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. 
    [self.tableView reloadData]; 
} 
*/ 


#pragma mark - 
#pragma mark Memory management 

- (void)didReceiveMemoryWarning { 
    // Releases the view if it doesn't have a superview. 
    [super didReceiveMemoryWarning]; 

    // 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 { 
    [fetchedResultsController_ release]; 
    [managedObjectContext_ release]; 
    [super dealloc]; 
} 


@end 

回答

2

我看到你返回數組,而不是一個單元格,你可以改變你的代碼是這樣的:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

static NSString *CellIdentifier = @"Cell"; 

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) { 
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease]; 
} 

// Set up the cell... 
cell.text = @"Value"; 

return cell; 
} 
相關問題