从另一个视图控制器调用int变量

时间:2012-01-13 04:01:16

标签: objective-c ios xcode

CatsTableViewController.h

@interface CatsTableViewController : UITableViewController {
  NSMutableArray *categoriesArray;
  int catInt;
}
@property int catInt;
@end

我已在我的CatsTableViewController.m中合成了它,并且我在视图中有#import "CatsTableViewController.h",我想在(CodesTableViewController.m)中调用此int。

详细信息:

这个int跟踪要加载到CodesTableViewController.m的{​​{1}}中的数组。 if语句可帮助应用确定要在TableView使用哪个数组计数以及在numberOfRowsInSection使用哪个数组。

所以我相信问题是如何从另一个cellForRowAtIndexPath调用此变量?

2 个答案:

答案 0 :(得分:1)

您可能还需要考虑使用NSUserDefaults来存储此int值。

NSUserDefaults Class Reference包含让您入门的所有信息。除了丰富的信息之外,还有一个简单的示例,说明如何保存和检索int(这适用于floatBOOLNSString,{ {1}},NSDateNSData):

NSArray

答案 1 :(得分:0)

如果您引用了类CatsTableViewController的实例,例如,名为catsController,那么您可以调用:

int localCatInt = [catsController catInt]; // your array index
相关问题