如何在另一个类中使用变量 [英] How to use a variable in another class

查看:136
本文介绍了如何在另一个类中使用变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好.
我刚刚学习了一个星期的Object C iPhone,但是还没有如何使用另一个类中的变量.例如:我有2个类RootViewControllor.h和BooksViewControllor.m
在RootViewControllor.h的声明如下:
@interface RootViewControllor:IUTableViewControllor {
NSArray * authorList;
}

@property(保留)NSArray * authorList;
@end

现在我想在BooksViewControllor.m上使用变量authorList t来获取或为其设置值,这意味着authorList可以同时用于RootViewControllor.m和BooksViewControllor.m


请帮我解决这个问题!

Hi All.
I have just study Object C iPhone for a week.But I not yet how to use a variable from another class. Ex: I have 2 class RootViewControllor.h and BooksViewControllor.m
at RootViewControllor.h was declared as below:
@interface RootViewControllor : IUTableViewControllor{
NSArray *authorList;
}

@property (retain) NSArray *authorList;
@end

Now I want to at BooksViewControllor.m I can use variable authorList t to get or set value to it, that mean is authorList can be used both RootViewControllor.m and BooksViewControllor.m


Please help me this problem!

Thanks in advance.

推荐答案

1)您需要在RootViewControllor.m文件中合成变量

@synthesize authorList;


2)并且您必须在BooksViewControllor.m中实现RootViewControllor.h


3)现在,您可以使用RootViewControllor对象访问BooksViewControllor.m中的authorList.
1) You need to synthesize the variable in RootViewControllor.m file

@synthesize authorList;


2) and u have to implement the RootViewControllor.h in BooksViewControllor.m


3) Now you can access the authorList in BooksViewControllor.m using RootViewControllor object.


这篇关于如何在另一个类中使用变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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