Hello I am brand new to xCode and iPhone development. I have two different TableView controls on one page. I have NSArray #1 that needs to be the datasource of TableView #1 and NSArray #2 that needs to be the datasource for TableView #2.
The only trouble is that NSArray#1 populates both TableView1 and TableView2. I looked through the code and can’t seem to find where you can distinguish which NSArray belongs to each TableView.
Any help will be appreciated. Thanks in advance!
@interface GrainBinContentsEstimatorViewController : UIViewController
<UITableViewDelegate, UITableViewDataSource>
{
UITableView *tableViewGrainBinType;
UITableView *tableViewGrainType;
}
@property (strong, nonatomic) NSArray *arrayGrainBinTypes;
@property (strong, nonatomic) NSArray *arrayGrainTypes;
@property (nonatomic, retain) UITableView *tableViewGrainBinType;
@property (nonatomic, retain) UITableView *tableViewGrainType;
@implementation GrainBinContentsEstimatorViewController
@synthesize arrayGrainBinTypes, arrayGrainTypes, tableViewGrainBinType, tableViewGrainType;
- (void)viewDidLoad
{
[super viewDidLoad];
self.arrayGrainBinTypes = [[NSArray alloc]
initWithObjects:@"RF", @"RC45", @"RC60", nil];
self.arrayGrainTypes = [[NSArray alloc]
initWithObjects:@"Wheat", @"Corn", @"Soybeans", @"Rice", @"Milo", @"Barley", nil];
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
return @"Select Bin Type";
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [self.arrayGrainBinTypes count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = [self.arrayGrainBinTypes objectAtIndex: [indexPath row]];
return cell;
}
In every delegate method (callback) the caller (tableview) is passed as a parameter. So you can switch based on this parameter like:
You get the idea…