Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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:

  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:

// 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.
share|improve this question
    
you are just initialize it, pass the getting values and make objects for display // Pass navigation list !!! IGANavListTableViewController *listObj = [[IGANavListTableViewController alloc]init]; –  Vineesh TP Mar 20 at 12:21
    
Sorry. I do not quite understand. I initialize it and then pass to UITableViewController by using [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
    
Changed the code but it is not working (see the update in the original message) –  Igor Tupitsyn Mar 20 at 23:59
    
@IgorTupitsyn use a property –  max_ Mar 21 at 0:02
    
I have in the .h file: @property (nonatomic,retain) NSMutableArray *navigationList; And in the implementation file: @synthesize navigationList –  Igor Tupitsyn Mar 21 at 0:14
show 3 more comments

1 Answer

OK. I solved the issue by passing the data through the prepareForSegue method and implementing the segue in IBAction using performSegueWithIdentifier method. Thanks everyone for trying to help.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.