从其他类访问NSMutableArray [英] Access NSMutableArray from a different class

查看:116
本文介绍了从其他类访问NSMutableArray的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类,其中形成了一个NSMutableArray对象,如下所示:

I have a class where a NSMutableArray object is formed, as so:

navBarColour = [[NSMutableArray alloc] initWithObjects:colourOfNavBar, nil];

然后我有另一个类,它正确地添加了第一个类,但它不会让我从第一个类访问NSMutableArray。这行代码:

I then have another class, which has the first class added to it properly, but it won't let me access the NSMutableArray from the first class. This line of code:

NSLog(@"%@", [HandlingPalettes.navBarColour objectAtIndex:0]);

退货:

预期':'在'。'标记之前

expected ':' before '.' token

但是:

NSLog(@"%@", [navBarColour objectAtIndex:0]);

可以在原始班级中使用。

would work in the original class.

我在这里做错了什么?

推荐答案

点符号在c ++或java的目标c中的使用方式不同。在objective-c中,它是访问属性的简写。你需要首先定义一个objective-c属性,如下所示:

The dot notation is used differently in objective c that from c++ or java. In objective-c it is shorthand for accessing a property. You need to have defined a objective-c property first, like this:

在.h文件中(INSIDE接口标记)

in the .h file (INSIDE the interface tag)

@property (nonatomic, retain) NSMutableArray *navBarColor;

(在实施标签内)

@synthesize navBarColor;

只有这样才能使用点表示法访问数组。

Only then can you access the array with the dot notation.

这篇关于从其他类访问NSMutableArray的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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