I have a ViewController where I enter a key through a textBox. The entered key pulls out all available records from a database where the same key is found. The list of the records forms NSMutableArray that I pass to UITableViewController, where the user can pick one. Then on the initial ViewController, this value should be selected.
Two issues:
1. Is there a way to open the TableViewController as modal and programmatically (not with the StoryBoard)? I have some "if" statements there that should control whether the TableViewController opens.
2. I cannot pass the array from the ViewController to TableViewController. Since I have no answer for question 1, I am doing it using another button (test). NSLog in UITableViewController tells me that the array there is null.
UIViewController.h:
UIViewController.mm
UITableViewController.h
UITableViewController.mm
In the end, I have:
I have been fighting this dilemma for a week already, although it should be a simple thing to do. I would really appreciate people's help!
Two issues:
1. Is there a way to open the TableViewController as modal and programmatically (not with the StoryBoard)? I have some "if" statements there that should control whether the TableViewController opens.
2. I cannot pass the array from the ViewController to TableViewController. Since I have no answer for question 1, I am doing it using another button (test). NSLog in UITableViewController tells me that the array there is null.
UIViewController.h:
Code:
@interface IGAViewController : UIViewController <UITableViewDataSource, UITableViewDelegate> {
NSString *navigationPoint;
NSMutableArray *navigationList; // List of all navigation points with the same name
}
@property (nonatomic,retain, getter=passNavigationList) NSMutableArray *navigationList;
@property (nonatomic,retain) NSString *navigationPoint;
// Return navigation list
-(NSMutableArray *) passNavigationList;
UIViewController.mm
Code:
@implementation IGAViewController
@synthesize navigationPoint, navigationList;
// Return navigation list
-(NSMutableArray *) passNavigationList {
return navigationList;
NSLog(@"NAVIGATION LIST AGAIN: %@", navigationList);
}
// Add a Navigation Point
-(IBAction) addIcaoNavigation:(id)sender {
// Setting up the path to the navigation points database
pathNav = [[NSBundle mainBundle] pathForResource:@"navdata_nav"
ofType:@"txt"];
// Text entered in the textfield is assigned as the Navigation Point
navigationPoint = txtNavIcao.text;
// If the Departure airport is not determined, this will give an error. Determine Departure first.
if ([txtDepIcao.text isEqual:@""] || portDeparture == nil) {
// Pop-up message that the airport was not found
UIAlertView* portNotFoundMsg;
portNotFoundMsg = [[UIAlertView alloc] initWithTitle:@"No Departure airport"
message:@"Select the Departure airport first"
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil, nil];
[portNotFoundMsg show];
}
else {
// Create an object for the Navigation Points and getting data
IGDNavigation* navObj = [[IGDNavigation alloc] initWithName: navigationPoint navdataPath: pathNav];
// Creating a list of all points with the same code sorted by the distance from departure
navigationList = [navObj navDataWithPreviousLatitude:depLatitude PreviousLongitude:depLongitude];
NSLog(@"NAVIGATION LIST: %@", navigationList);
// Open the UITableViewController
// THIS IS WHERE HELP FOR Q1 IS NEEDED
NSLog(@"NAVIGATION POINT: %@", navigationPoint);
UITableViewController.h
Code:
@interface IGANavListTableViewController : UITableViewController {
NSString *navPoint;
NSMutableArray *listOfNavPoints;
}
@property (nonatomic,strong) NSMutableArray *listOfNavPoints;
@property (nonatomic,strong) NSString *navPoint;
UITableViewController.mm
Code:
@implementation IGANavListTableViewController
@synthesize listOfNavPoints, navPoint;
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Pass the list of Navigation Points
IGAViewController *mainObj = [[IGAViewController alloc] init];
// listOfNavPoints = [[NSMutableArray alloc] initWithObjects:@"111",@"222",@"333", nil]; // THIS WORKS!
listOfNavPoints = [mainObj passNavigationList]; // THIS DOES NOT WORK!
// THIS IS JUST TO CHECK IF PASSING WORKS
navPoint = mainObj.navigationPoint;
NSLog(@"VIEW DID LOAD: %@", navPoint);
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [listOfNavPoints count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
//UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
// Configure the cell...
if (cell==nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
}
cell.textLabel.text = [listOfNavPoints objectAtIndex:indexPath.row];
return cell;
}
In the end, I have:
Code:
NAVIGATION LIST: (
"NDB|GIG|GERING|41.944356|-103.683|341 Khz|639 nm",
"NDB|GIG|GINGIN|-31.459722|115.865556|372 Khz|8275 nm"
)
NAVLIST DID LOAD: (null)
I have been fighting this dilemma for a week already, although it should be a simple thing to do. I would really appreciate people's help!