我是新來的iPhone開發,並一直在努力弄清楚爲什麼我的表不工作。這可能與Core Data有關,我不確定。 viewDidLoad方法在開始工作正常,但是當我嘗試滾動表視圖,當下一行出現,我得到的錯誤:NSCFString objectAtIndex無法識別的選擇器發送到實例0x5d52d70
NSInvalidArgumentException「的,理由是:」 - [NSCFString objectAtIndex:]:無法識別的選擇發送到實例0x5d52d70'
我查看或者Controller.h:
#import <UIKit/UIKit.h>
#define kTableViewRowHeight 66
@interface RostersViewController : UIViewController
<UITableViewDelegate, UITableViewDataSource> {
NSArray *objects;
}
@property(nonatomic,retain) NSArray *objects;
@end
我查看Controller.m或者:
#import "RostersViewController.h"
#import "CogoAppDelegate.h"
#import "TeamCell.h"
@implementation RostersViewController
@synthesize objects;
- (void)viewDidLoad {
CogoAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
NSManagedObjectContext *context = [appDelegate managedObjectContext];
NSEntityDescription *entityDescription = [NSEntityDescription entityForName:@"Teams" inManagedObjectContext:context];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:entityDescription];
NSError *error;
objects = [context executeFetchRequest:request error:&error];
if (objects == nil)
{
NSLog(@"There was an error!");
// Do whatever error handling is appropriate
}
[request release];
UIApplication *app = [UIApplication sharedApplication];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationWillTerminate:)
name:UIApplicationWillTerminateNotification
object:app];
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[objects release];
[super dealloc];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [objects count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:@"cell"];
id currObj = [objects objectAtIndex:indexPath.row];
cell.textLabel.text = [currObj valueForKey:@"name"];
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return kTableViewRowHeight;
}
@end
感謝您的任何幫助。非常感謝。
Gotcha。它現在有效。謝謝你的幫助。 – quiksil12 2010-07-03 13:40:02