【问题标题】:how to call function from another class and reload that view from the current class?如何从另一个类调用函数并从当前类重新加载该视图?
【发布时间】:2012-05-28 07:10:17
【问题描述】:

我正在开发一个使用凹凸技术的应用程序。我确实有四个选项卡,其中一个是表格视图。我在应用程序委托类中编写了这个凹凸 API,以便当应用程序打开时它应该能够传输data.Transfer 功能正常工作。但问题是我将数据插入 sq-lite 并且来自 sqlite 的数据显示在选项卡栏项目视图之一中。因此,当用户选择此选项卡栏项目并接收我想插入数据并使用新更改重新加载视图。正如插入之前所说的那样,我正在工作。但问题是重新加载视图。有人可以帮我解决这个问题吗?

【问题讨论】:

    标签: iphone ios ios5 xcode4.3


    【解决方案1】:

    您可以使用 NSOperation 在后台执行插入操作,并在您插入/编辑记录时发布通知。将侦听器添加到您正在显示数据的视图控制器。

    所以当控制器收到通知时,它会调用该方法从数据库中重新加载数据。

    @implementation MyClass
    
    - (void) dealloc
    {
        [[NSNotificationCenter defaultCenter] removeObserver:self];
        [super dealloc];
    }
    
    - (id) init
    {
        self = [super init];
        if (!self) return nil;
    
    
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadData:) name:@"COREDATA_OBJECT_EDITED" object:nil];
    
        return self;
    }
    
    - (void) reloadData:(NSNotification *) notification
    {
        if ([[notification name] isEqualToString:@"COREDATA_OBJECT_EDITED"])
            {
                //load records from database and reload tableview
            }
    }
    
    @end
    
    
    
    
    
    //Method where you are saving data objects in some other class
    
    - (void) saveDataObject
    {
    
        //Save Data object, if saved successfully then post notification to listener to reload the data
        // All instances of MyClass will be notified
        [[NSNotificationCenter defaultCenter] postNotificationName:@"COREDATA_OBJECT_EDITED" object:self];
    
    }
    

    【讨论】:

    • 你能告诉我一些教程吗?我是这个 iPhone 开发的新手。
    • @JitendraSingh 在stackoverflow上欢迎先生。你认出我了吗……?
    猜你喜欢
    • 1970-01-01
    • 2013-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多