I have a ViewController where I enter a key through a textBox. The entered key pulls out all available records from a database whether the same key is found. The list of the records forms NSMUtableArray that I pass to TableViewController, where the user can pick one. Then on the initial ViewController, this value should be selected.
Two issues:
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.
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:
// 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
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); // This works, array created
// Pass navigation list !!!
IGANavListTableViewController *listObj = [[IGANavListTableViewController alloc]init];
[listObj obtainNavList:navigationList];
// Open the UITableViewController
// THIS IS WHERE YOUR HELP OF Q1 IS NEEDED.
UITableViewController:
- (void)viewDidLoad
{
[super viewDidLoad];
// Pass the list of Navigation Points
IGAViewController *mainObj = [[IGAViewController alloc] init];
NSLog(@"VIEW DID LOAD: %@", listOfNavPoints); // listOfNavPoints is nul.
// The following would work though
/*
listOfNavPoints = [[NSMutableArray alloc] initWithObjects:
@"AAAA",
@"BBBB",
@"CCCCC",
nil];
*/
}
- (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;
}
// Created this method just in case, although it should be enough to have a setter. Either do not work.
-(void) obtainNavList: (NSMutableArray *) navList {
listOfNavPoints = navList;
}
UPDATE:
Changed the code, but it is still not working. Why???!!!
- (void)viewDidLoad {
[super viewDidLoad];
// Pass the list of Navigation Points
IGAViewController *mainObj = [[IGAViewController alloc] init];
listOfNavPoints = [[NSMutableArray alloc] init];
listOfNavPoints = mainObj.navigationList;
NSLog(@"VIEW DID LOAD: %@", listOfNavPoints);
}
NAVIGATION LIST: (
"NDB|GIG|GERING|41.944356|-103.683|341 Khz|639 nm",
"NDB|GIG|GINGIN|-31.459722|115.865556|372 Khz|8275 nm"
)
VIEW DID LOAD null.
[listObj obtainNavList:navigationList];
May be I need to do the following in the viewDidLoad:listOfNavPoints = mainObj.navigationList
? I might have tried though and it did not work... I will try it again – Igor Tupitsyn Mar 20 at 21:23@property (nonatomic,retain) NSMutableArray *navigationList;
And in the implementation file:@synthesize navigationList
– Igor Tupitsyn Mar 21 at 0:14