我收到此错误代码" [__ NSArrayM myNameChoices]:无法识别的选择器发送到实例0x8c99060"在self.mySelectedCell = currentRow.myNameChoices;线。我不确定为什么。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
MyDataChoices *currentRow = self.arrayNames[indexPath.row];
//unrecognized selector sent to instance
self.mySelectedCell = currentRow.myNameChoices;
[self performSegueWithIdentifier:@"unwindSegueAction" sender:self];
}
正在填充数组arrayNames:
- (void)viewDidLoad
{
[super viewDidLoad];
self.myTableView.delegate = self;
self.myTableView.dataSource = self;
//does not work with more than one array in the array
self.arrayNames = [NSMutableArray arrayWithObjects:
[NSMutableArray arrayWithArray:@[[MyDataChoices itemWithNewName:@"Apples"]]],
[NSMutableArray arrayWithArray:@[[MyDataChoices itemWithNewName:@"Oranges"]]], nil];
}
包含mySelected单元格的.h代码
@interface ChoicesTableViewController : UITableViewController
@property (strong, nonatomic) NSString *mySelectedCell;
@end
包含myDataChoices对象的.h代码
@interface MyDataChoices : NSObject
@property (strong, nonatomic) NSString *myNameChoices;
+ (MyDataChoices *)itemWithNewName:(NSString *)myNameChoices;
@end
包含myDataChoices对象的.m代码
@implementation MyDataChoices
+ (MyDataChoices *)itemWithNewName:(NSString *)myNameChoices
{
MyDataChoices *object = [[MyDataChoices alloc] init];
object.myNameChoices = myNameChoices;
return object;
}
@end
感谢您提供的信息!
答案 0 :(得分:2)
self.arrayNames
正在回复NSMutableArray
个,而不是MyDataChoices
个对象,正如您所期待的那样。该错误是因为NSMutableArrays
没有myNameChoices
属性。
在viewDidLoad
:
self.arrayNames = [NSMutableArray arrayWithObjects:
[MyDataChoices itemWithNewName:@"Apples"],
[MyDataChoices itemWithNewName:@"Oranges"], nil];