1
我有一个非常简单的任务: 将textField的内容添加到NSMutableArray。问题是数组正在返回nill。我相信这与我使用的数组被声明为实例变量的事实有关。为什么我的NSMutableArray返回nill?
/*
IBOutlet NSTextField *textField;
IBOutlet NSTabView *tableView;
IBOutlet NSButton *button;
NSMutableArray *myArray;
*/
#import "AppController.h"
@implementation AppController
-(IBAction)addNewItem:(id)sender
{
NSString *string = [textField stringValue];
NSLog(@"%@",string);
[myArray addObject:string];
NSLog(@"%d",[myArray count]);//this outputs 0 why is that?
}
可能的重复http://stackoverflow.com/questions/633699/nsmutablearray-count-always-returns-zero – itsmatt 2010-04-13 21:11:17
你是如何初始化数组?你正在初始化它吗? – 2010-04-14 00:20:34