2010-07-03 4 views
2

저는 iPhone 개발에 익숙하지 않아서 테이블이 왜 작동하지 않는지 알아 내려고 노력하고 있습니다. 핵심 데이터와 관련이있을 수 있습니다. 확실하지 않습니다. viewDidLoad 메서드는 처음에는 잘 작동하지만 다음 행이 나타나면 테이블 뷰를 스크롤하려고 할 때 오류가 발생합니다.NSCFString objectAtIndex 인스턴스로 전송 된 인식 할 수없는 선택기 0x5d52d70

NSInvalidArgumentException ', 이유 :'- [NSCFString objectAtIndex :] : 인식 할 수없는 선택기

#import <UIKit/UIKit.h> 
#define kTableViewRowHeight 66 

@interface RostersViewController : UIViewController 
<UITableViewDelegate, UITableViewDataSource> { 

NSArray *objects; 
} 
@property(nonatomic,retain) NSArray *objects; 
@end 

내보기 Controller.m :

01 인스턴스 0x5d52d70 '

내보기 Controller.h로 전송

#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 

도움 주셔서 감사합니다. 대단히 감사합니다. objects = [context executeFetchRequest:request error:&error]; 그런 다음 바르에 직접 저장하는 오토 릴리즈 객체를 반환 executeFetchRequest

self.objects = [context executeFetchRequest:request error:&error];에있는 viewDidLoad 변화에

답변

5

, 이것은 나중에에서 쓰레기 포인터로 바뀝니다. 그냥 문자열을 가리 키도록 결국 그렇게됩니다.

self.objects을 사용하면 합성 된 setter를 사용하고 그대로 유지합니다.

+0

Gotcha. 이제 작동합니다. 당신의 도움을 주셔서 감사합니다. – quiksil12

관련 문제