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