iOS TabBar应用程序中的全局变量 [英] Global variable in iOS TabBar Application

查看:82
本文介绍了iOS TabBar应用程序中的全局变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在xcode 4.2中创建ios应用. 我有数据库的外部文件.我不想在每个视图中下载数据.如何为标签栏应用程序创建一个全局变量?在关闭应用程序之前,我应该何时上传该数据库?

I am creating ios app in xcode 4.2. I have outside file with database. I dont wanna download data in every view. How should i create one global variable for tabbar application? And when should i upload this database before closing of application?

推荐答案

我使用这样的单调:在数据库类中,使用一些数据数组,我实现了共享方法:

I use singletones like this: in class DataBase with some arrays of data i implement share method:

+(id)share
{
    static id share = nil;

    if (share == nil) {
        share = [[self alloc] init];
    }

    return share;
}

,然后在某些类中:self.dataBase = [Database share];

and then in some classes: self.dataBase = [DataBase share];

这篇关于iOS TabBar应用程序中的全局变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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