我聲明瞭在firstviewcontroller陣列等添加對象,具有自定義委託功能給錯誤
@interface ClassesList : UIViewController
{
NSMutableArray *className;
}
@property (retain,nonatomic) NSMutableArray *className;
並限定委託方法在下一視圖控制器對象添加到數組的NSMutableArray
@protocol Createclass <NSObject>
-(void)addnewObject:(NSString*)string;;
@end
併發送字符串與文本文件的字符串
[self.delegate addnewClass:_className.text];
while calling this met OD在firstviewcontroller它顯示錯誤
NSInvalidArgumentException', reason: '-[__NSArrayI addObject:]: unrecognized selector sent to instance
這裏是我的編輯
-(void)addnewClass:(NSString *)string
{
[className addObject:string];
[self.table reloadData];
}
我越來越從plist文件存儲類
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"classesArray.plist"];
NSDictionary *StudentDict=[[NSDictionary alloc]initWithContentsOfFile:path];
NSArray *See = StudentDict[@"alldata"];
className = [[NSMutableArray alloc]init];
className= [See valueForKey:@"class_name"];
您能否在您的firstViewController中發佈 - (void)addnewObject:(NSString *)字符串的代碼 – AntonijoDev
Adn yout協議方法被稱爲addnewObject而不是addnewClass,所以它應該是[self.delegate addnewObject:_className。文本]; – AntonijoDev
@AntonijoDev對不起addnewObject只是爲發佈問題而改變 – user3595019