Ios SharedInstance为非最新的全局变量
我有一个全局变量的小问题。这是课堂。h:Ios SharedInstance为非最新的全局变量,ios,uitableview,global-variables,uitabbar,Ios,Uitableview,Global Variables,Uitabbar,我有一个全局变量的小问题。这是课堂。h: #import <Foundation/Foundation.h> @interface GlobalVariables : NSObject{ NSMutableArray *categories; } @property (nonatomic, retain) NSMutableArray *categories; + (GlobalVariables *)sharedInstance; @end 因此,我现在有4个带有
#import <Foundation/Foundation.h>
@interface GlobalVariables : NSObject{
NSMutableArray *categories;
}
@property (nonatomic, retain) NSMutableArray *categories;
+ (GlobalVariables *)sharedInstance;
@end
因此,我现在有4个带有UITableViewController
的选项卡,每个选项卡都需要来自上面类别数组的数据
问题是,在第一个选项卡中,一个更新算法正在运行以更新此阵列,但只有在我重新启动应用程序时,此更新才在选项卡2中可用
如何在所有其他选项卡中立即看到这些更改?尝试将共享实例及其类别的值记录在两个看起来不同步的位置。实例地址应该显示您是否真的拥有相同的对象。好的,它是相同的对象,但我在日志中发现了其他东西。。。我的应用程序中有一个逻辑错误。第二个视图试图解析数据,即使第一个视图尚未完成数据的生成。。。现在它工作得很好…谢谢你
#import "GlobalVariables.h"
@implementation GlobalVariables
@synthesize categories;
+ (GlobalVariables *)sharedInstance
{
// the instance of this class is stored here
static GlobalVariables *myInstance = nil;
// check to see if an instance already exists
if (nil == myInstance) {
myInstance = [[[self class] alloc] init];
// initialize variables here
}
// return the instance of this class
return myInstance;
}
@end