Iphone NsMutableArray无理由更改为UITableViewCellContentView

Iphone NsMutableArray无理由更改为UITableViewCellContentView,iphone,objective-c,ios,nsmutablearray,Iphone,Objective C,Ios,Nsmutablearray,我有个问题。在UITableViewController的viewDidLoad方法中,我有: myfields = [NSMutableArray array]; for (int x = 0; x < 10; x++) { UITextField * field = [[UITextField alloc] initWithFrame:CGRectMake(130,12,150,25)]; field.backgroundColor = [UIC

我有个问题。在UITableViewController的viewDidLoad方法中,我有:

myfields = [NSMutableArray array];
    for (int x = 0; x < 10; x++) {
        UITextField * field = [[UITextField alloc] initWithFrame:CGRectMake(130,12,150,25)];
        field.backgroundColor = [UIColor clearColor];
        field.font = [UIFont systemFontOfSize:15];
        field.delegate = [[OptionFieldDelegate alloc] init];
        [myfields addObject: field];
    }
    NSLog(@"myfields array - %@",myfields);
这是输出:

2010-11-13 00:58:13.808 Poll Maker[1803:207] Array = <UITableViewCellContentView: 0x6a35b10; frame = (10 1; 300 43); layer = <CALayer: 0x6a3e680>>
2010-11-13 00:58:13.809 Poll Maker[1803:207] class - UITableViewCellContentView
2010-11-13 00:58:13.809 Poll Maker[1803:207] 0 - 0
2010-11-13 00:58:13.810 Poll Maker[1803:207] -[UITableViewCellContentView objectAtIndex:]: unrecognized selector sent to instance 0x6a35b10
2010-11-13 00:58:13.812 Poll Maker[1803:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITableViewCellContentView objectAtIndex:]: unrecognized selector sent to instance 0x6a35b10'
2010-11-13 00:58:13.808民意测验制作者[1803:207]数组=
2010-11-13 00:58:13.809民意调查制作人[1803:207]类-UITableViewCellContentView
2010-11-13 00:58:13.809民意调查制作人[1803:207]0-0
2010-11-13 00:58:13.810投票制作者[1803:207]-[UITableViewCellContentView对象索引:]:发送到实例0x6a35b10的选择器无法识别
2010-11-13 00:58:13.812民意调查制作人[1803:207]***由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:'-[UITableViewCellContentView objectAtIndex::]:无法识别的选择器发送到实例0x6a35b10'

我很困惑。有人能帮我吗?谢谢。

您犯了内存管理错误。如果要在第一个方法结束后保留数组,则必须保留该数组


在您的情况下,数组曾经所在的内存(在自动释放池释放之前)被UITableViewCell的子视图覆盖。

您犯了内存管理错误。如果要在第一个方法结束后保留数组,则必须保留该数组


在您的情况下,数组曾经所在的内存(在自动释放池释放之前)被UITableViewCell的子视图覆盖。

Ole Begemann可能已经找到了问题的原因,但是当您遇到内存管理问题时(选择器被发送到错误的实例是内存管理问题的标志),您可以做很多事情:

  • 重新阅读Cocoa,并确保您正在跟踪它们
  • 运行。这通常会发现您忽略了内存管理规则的地方
  • 尝试使用以确定是否[以及何时]向未分配的实例发送消息

  • Ole Begemann可能已经找到了问题的原因,但是当您遇到内存管理问题(选择器被发送到错误的实例是内存管理问题的迹象)时,您可以做很多事情:

  • 重新阅读Cocoa,并确保您正在跟踪它们
  • 运行。这通常会发现您忽略了内存管理规则的地方
  • 尝试使用以确定是否[以及何时]向未分配的实例发送消息

  • 非常感谢你。我早该知道的。非常感谢你。我应该知道的。谢谢你的建议。我在客观方面越来越好。。。慢慢来,谢谢你的建议。我在客观方面越来越好。。。慢速地
    NSLog(@"Array = %@",myfields);
                        NSLog(@"class - %@",NSStringFromClass([myfields class]));
                        NSLog(@"0 - %i",[indexPath row] - 2);
                        NSLog(@"1 - %@",[myfields objectAtIndex:[indexPath row] - 2]);
                        [[cell contentView] addSubview: [myfields objectAtIndex:[indexPath row] - 2]];
    
    2010-11-13 00:58:13.808 Poll Maker[1803:207] Array = <UITableViewCellContentView: 0x6a35b10; frame = (10 1; 300 43); layer = <CALayer: 0x6a3e680>>
    2010-11-13 00:58:13.809 Poll Maker[1803:207] class - UITableViewCellContentView
    2010-11-13 00:58:13.809 Poll Maker[1803:207] 0 - 0
    2010-11-13 00:58:13.810 Poll Maker[1803:207] -[UITableViewCellContentView objectAtIndex:]: unrecognized selector sent to instance 0x6a35b10
    2010-11-13 00:58:13.812 Poll Maker[1803:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITableViewCellContentView objectAtIndex:]: unrecognized selector sent to instance 0x6a35b10'