我在应用程序中有一个单例,需要使用另一个类的争论来调用它的函数,但是当我调用它时,传递了 nil 争论......这是代码:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
NSLog([Singleton sharedMySingleton].test);
NSDictionary *story = [self.filters objectAtIndex: indexPath.row];
MainAppRecord *record = [[[MainAppRecord alloc]init]retain];
record.name = [story objectForKey:@"Name"];
record.searchUrl = [story objectForKey:@"SearchUrl"];
record.icon = [imageCash objectForKey:indexPath];
[[Singleton sharedMySingleton] changeMainFilterTo:record atPosition:indexOfFilterToChange];
}
这是 Singleton.h 及其功能:
@interface Singleton : NSObject {
NSMutableArray *mainFilters;
NSString *test;
}
@property (nonatomic, retain) NSMutableArray *mainFilters;
@property (nonatomic, retain) MainAppRecord *filterToChange;
-(void) initWithPlist;
-(void) saveToPlist;
-(void)changeMainFilterTo:(MainAppRecord*)record atPosition:(int)position;
+(Singleton *)sharedMySingleton;
@end
-(void)changeMainFilterTo:(MainAppRecord*)record atPosition:(int)position
{
[mainFilters insertObject:record atIndex:position];
}
该应用程序崩溃
2012-10-20 16:24:52.789 TableView[1957:207]-[__NSArrayI insertObject:atIndex:]:无法识别的选择器发送到实例 0x68410f0
谢谢