开发者

Global array loses values after exiting method

At the top of my .m file I have

static NSMutableArray *name;

I load a bunch of values into my *name array inside my viewDidLoad method.

I have a slider that can modify the values ins开发者_JAVA百科ide this array. The slider method is only called when the value of the slider changes. However, I ran this code and every time my program exits the viewDidLoad method I lose the values that were added to the global variable name. I can see that they were there before exiting the viewDidLoad method.

What am I doing wrong?

EDIT: Inside viewDidLoad

if (name == nil)
    name = [NSMutableArray array];
UITextField *nameTemp = [[UITextField alloc] initWithFrame:CGRectMake(20,20,20,20)];
nameTemp.returnKeyType = UIReturnKeyDone;
etc
[self.view addSubview: nameTemp];
[name addObject:nameTemp]
[nameTemp release];


[NSMutableArray array] creates an autoreleased array that apparently is being released at the end of your viewDidLoad method. Try using [[NSMutableArray alloc] init] or [[NSMutableArray array] retain] and see if the values persist after viewDidLoad returns.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜