在目标C通用阵列 [英] universal array in objective C

查看:98
本文介绍了在目标C通用阵列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在做我的第一个应用程序,并已使其在Android上,和我现在试图使其在iPhone上,但没有目标C的经验。该应用程序是除了一个组成部分,该数组超级简单。

I am making my first app, and already made it on android, and am now trying to make it on iphone, but have no objective c experience. The app is super simple except for one part, the array.

该应用程序有一个按钮,当pressed,需要信息存储到一个数组。我遇到的问题是,当我创建在该按钮单击操作发生的法阵,每一次我点击它会创建一个新的数组按钮,击败阵列的地步。当我做阵列的方法之外,它要么不被传递到方法(错误说未定义),或者,当我在.h文件中声明对象,程序编译,但是当我按下按钮它崩溃。

The app has a button, that when pressed, needs to store info into an array. The problem I am running into is that when I create the array in the method where the button-click actions take place, every time I click the button it creates a new array, defeating the point of the array. When I make the array outside of the method, it either doesn't pass into the method (error says undefined) or, when I declare the object in the .h file, the program compiles, but when I hit the button it crashes.

任何帮助将大大AP preciated。例子将是巨大的,但即使有人能指出我的事情向正确的方向抬头,这将救我脱离秃顶。

Any help would be greatly appreciated. Examples would be great, but even if someone could point me in the right direction of things to look up, that would save me from going bald.

推荐答案

尝试这样的事情(这不是ARC) -

Try something like this (this isn't ARC) -

@interface MyViewController : UIViewController {

    NSMutableArray *myArray;

}


@implementation MyViewController

-(id)init {

    self = [super init];

    if (self) {

        myArray = [[NSMutableArray alloc] init];

    }

    return self;

}


-(void)dealloc {

    [myArray release];

    [super dealloc];

}


-(IBAction)buttonPressed {

    [myArray addObject:someObject];

}

@end

这篇关于在目标C通用阵列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆