无法识别的选择器在阵列上发送到实例错误

时间:2014-10-23 19:44:27

标签: ios objective-c xcode cocoa

我收到此错误代码" [__ 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

感谢您提供的信息!

1 个答案:

答案 0 :(得分:2)

self.arrayNames正在回复NSMutableArray个,而不是MyDataChoices个对象,正如您所期待的那样。该错误是因为NSMutableArrays没有myNameChoices属性。

viewDidLoad

中尝试这样的事情
self.arrayNames = [NSMutableArray arrayWithObjects:
                       [MyDataChoices itemWithNewName:@"Apples"],
                       [MyDataChoices itemWithNewName:@"Oranges"], nil];