iphone - NSMutableArray 不更新

标签 iphone ios xcode

我对 iOS 还算陌生,我的数组遇到了困难,我正在使用 NSMutableArray,我已将数组放入 AppDelegate 中, 第一次在我的 viewController 中加载应用程序时,数组中还没有对象,我有一个设置将整数放入数组中, 但保存后数组未加载,但退出然后重新打开时,它将加载, 请有人解释一下我该如何解决以及为什么会这样? 我正在使用它tableview

应用程序委托(delegate)中:

self.integers = [NSMutableArray array];  
for(int i = 0; i <= 10; i++) 
{ .....
  }

加载中:

integers = ((AppDelegate *)[[UIApplication sharedApplication] delegate]).integers;

最佳答案

我的回答:

在代码中的某个地方有一个循环加载整数并将它们放入数组中,对吧? 您需要将该循环放入一个方法中,并在您想要将 UITableVIew 内容重置回其原始内容时再次调用它。 然后,您需要更新 AppDelegateviewController 中的数组,因此根据该方法所在的类,您需要使用以下方法将整数复制到另一个类

integers = ((AppDelegate *)[[UIApplication sharedApplication] delegate]).integers;

// your array then update
self.integerss = [NSMutableArray array];  

    for(int i = 0; i <= 10; i++) 
    { .....
      }

((AppDelegate *)[[UIApplication sharedApplication] delegate]).integers = self.integers;

使用最初用于数组的相同代码将所有整数放回原处,然后在 tableview 上调用 reloadData。 这将解决您的问题。

关于iphone - NSMutableArray 不更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11592251/

相关文章:

iphone - 如何设置表格 View 单元格适应标签?

iphone - 限制用户输入字符,并在ios中将每个输入的字母转换为大写字母

ios - 在 iOS 中从文件中获取图像

iphone - TabBar应用、CoreData相关应用崩溃

iphone - 如何从 plist 中获取乌尔都语单词?

ios - 转到另一个 View Controller TableView 单元格 xib

android - 如何将 Coldfusion 网站转换为 Native Mobile 应用程序

iphone - Instruments 是否显示 UIWebView 使用的内存?

iphone - stringWithContentsOfURL 和 HTTP 500 错误代码

iPhone app里面只有一个本地的HTML文件,怎么办?