-1

i'm new to ios. I have a ViewController class that scan a barcode and save the result into an NSMutableArray. Then i want to show the content of the Array in TableView, so need to use that Array in another class.

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 ????
}

Now, using objAppDelegate.objViewCont.dataSource i have access to the Array. The problem is that : i don't know how to populate the table using dataSource !

Dayton Wang
  • 2,332
  • 1
  • 12
  • 17
max85
  • 245
  • 1
  • 3
  • 8
  • probably you need to leant how to implement a proper _model-layer_, if passing data between classes causes such issue for you. (meanwhile, it is the thousandth post about the same thing, only on this site, anyway.) – holex Jun 05 '15 at 18:56
  • possible duplicate of [Passing Data between View Controllers](http://stackoverflow.com/questions/5210535/passing-data-between-view-controllers) – bgfriend0 Jun 05 '15 at 19:21

1 Answers1

0

If your issue is with how to display the contents of that array in the uitableview, you will need to connect the table to your viewcontroller's data source delegate and uitableview delegate.

Then you can use the delegate methods to specify the number of rows in each section depending on the size of your array, then use another delegate to specify what to display in each cell of that table view.

You can find a lot of interesting tutorials online with a quick google search. That's how I started

Here is an example: http://www.appcoda.com/ios-programming-tutorial-create-a-simple-table-view-app/

You will certainly use a lot of uitableviews in the future. It wouldn't hurt to take the time and learn how they work exactly.

Enjoy coding!

carlos16196
  • 706
  • 1
  • 7
  • 10