Iphone NSMutableArray未更新

Iphone NSMutableArray未更新,iphone,ios,xcode,Iphone,Ios,Xcode,我对iOS有点陌生,我的数组很难使用,我正在使用NSMutableArray,我已经将数组放入AppDelegate, 在我的viewController中首次加载应用程序时,数组中还没有对象,我有一个将整数放入数组的设置, 但保存后数组未加载,但退出后重新打开时,将加载, 请有人解释一下我如何解决这个问题,为什么会这样? 我正在使用它tableview 在应用程序委托中: self.integers = [NSMutableArray array]; for(int i = 0; i &l

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

应用程序委托中

self.integers = [NSMutableArray array];  
for(int i = 0; i <= 10; i++) 
{ .....
  }
我的答覆是:

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

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

//然后更新您的数组
self.integers=[NSMutableArray];

对于(int i=0;我认为这确实可以解决您的问题,但我也建议重新安排您的设计-我看不出应用程序委托应该与应用程序数据层有任何关系并持有一个整数数组的好理由。我的意思是,AppDelegate类不适用于您使用它的任何用途。开发人员倾向于将此我经常这样做是因为它是第一个运行的代码。我建议将此数据实体移动到管理数据的类中。
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;