我是新来的ios。 我有一个ViewController类,它扫描条形码并将结果保存到NSMutableArray中。然后我想在TableView中显示数组的内容,所以需要在另一个类中使用该数组。在类之间传递NSMutableArray
CODE:
APPDELEGATE.H
@property (nonatomic, strong) ViewController *objViewCont;
APPDELEATE.M
@synthesize objViewCont;
VIEWCONTROLLER.H
@property (nonatomic, retain) NSMutableArray *dataSource;
VIEWCONTROLLER.M
@synthesize dataSource;
...
NSString data = //result of scanning
[dataSource addObject:testData];
TABLEVIEWCONTROLLER.M
#import "ViewController.h"
#import "AppDelegate.h"
....
- (void)viewDidLoad {
[super viewDidLoad];
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"Cell"];
self.navigationItem.rightBarButtonItem = self.editButtonItem;
AppDelegate *objAppDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
// how to populate table with dataSource ????
}
现在,使用objAppDelegate.objViewCont.dataSource我可以访问阵列。问题是:我不知道如何使用dataSource填充表格!
如果在类之间传递数据导致您遇到此类问题,您可能需要如何实施适当的_model-layer_。 (同时,它是关于同一事物的第1,000个帖子,无论如何只有在这个站点上。) – holex
[View Controller之间传递数据]的可能重复(http://stackoverflow.com/questions/5210535/passing-data-between -view控制器) – bgfriend0