objective-c - 从 UIViewController 传递 NSArray

标签 objective-c ios uiviewcontroller nsarray

我在 UINavigationController 中有一个带有 NSMutableArray 的 rootView Controller 。我需要在未经许可的情况下将数组副本传递给另一个 ViewController。

所以我在一些 ViewController 中执行以下操作:

- (void)setArrExercises:(NSArray *) arrExercs {
     // arrExercs NSMutableArray of my custom objects from rootViewController
     arrExec = [[NSArray alloc] initWithArray:arrExercs];
}

数组创建好了,但是在TableView的委托(delegate)方法中:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{   
    return [arrExec count];
}

没有项目。

最佳答案

也许你必须这样尝试

-(void) setArrExercises:(NSArray *) arrExercs {
     // arrExercs NSMutableArray of my custom objects from rootViewController
     NSArray* arrExec = [[NSArray alloc]init];
     for( int i=0; i<[arrExercs count]; ++i )
        [arrExec addObject:arrExec[i]];
  }

关于objective-c - 从 UIViewController 传递 NSArray,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6120866/

相关文章:

objective-c - 如何在不解压缩到磁盘的情况下直接从 zip 中读取图像文件?

objective-c - 使用某个对象类的类方法

iphone -- 在第二代 iPod Touch 上运行 XCode 4.2 和 iOS 5 SDK

objective-c - 有没有办法调整 iPhone 中模态视图屏幕的大小

ios - 不区分大小写的字符串搜索 - iphone

ios - Swift - 如何在使用 AVFoundation 录制音频时消除延迟

ios - PhaseScriptExecution 失败,退出代码非零

objective-c - 为什么在添加 subview Controller 后需要再次添加 subview ?

ios - Swift 2.2 - 更新 UILabel 抛出 "unexpectedly found nil while unwrapping an optional value"

ios - subview Controller 必须有一个共同的父 View Controller ?