我有一個bissare問題。在一個UITableViewController的viewDidLoad方法,我有:NsMutableArray無理由更改爲UITableViewCellContentView
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);
這給出了這樣的輸出:
myfields array - (
"<UITextField: 0x6a35b50; frame = (130 12; 150 25); clipsToBounds = YES; opaque = NO; layer = <CALayer: 0x6a35c60>>",
"<UITextField: 0x6a36820; frame = (130 12; 150 25); clipsToBounds = YES; opaque = NO; layer = <CALayer: 0x6a367f0>>",
"<UITextField: 0x6a374e0; frame = (130 12; 150 25); clipsToBounds = YES; opaque = NO; layer = <CALayer: 0x6a374b0>>",
"<UITextField: 0x6a382e0; frame = (130 12; 150 25); clipsToBounds = YES; opaque = NO; layer = <CALayer: 0x6a382b0>>",
"<UITextField: 0x6a38ea0; frame = (130 12; 150 25); clipsToBounds = YES; opaque = NO; layer = <CALayer: 0x6a38e70>>",
"<UITextField: 0x6a39950; frame = (130 12; 150 25); clipsToBounds = YES; opaque = NO; layer = <CALayer: 0x6a39a60>>",
"<UITextField: 0x6a3a630; frame = (130 12; 150 25); clipsToBounds = YES; opaque = NO; layer = <CALayer: 0x6a3a600>>",
"<UITextField: 0x6a3b1f0; frame = (130 12; 150 25); clipsToBounds = YES; opaque = NO; layer = <CALayer: 0x6a3b1c0>>",
"<UITextField: 0x6a3bdb0; frame = (130 12; 150 25); clipsToBounds = YES; opaque = NO; layer = <CALayer: 0x6a3bd80>>",
"<UITextField: 0x6a3c970; frame = (130 12; 150 25); clipsToBounds = YES; opaque = NO; layer = <CALayer: 0x6a3c880>>"
)
這很好,但下位是沒有的。我不碰這個數組之前,我需要,但在 - 的tableView:的cellForRowAtIndexPath:方法我有這樣的:
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'
我很迷茫。誰能幫我?謝謝。
謝謝你。我應該知道這一點。 – 2010-11-13 01:41:06