meariMD
meariMD

Reputation: 115

How to populate an NSMutableArray with entered Text Field

The problem that I'm having with this is that after I enter the text into the textfield, I have to leave the page and go onward to select certain options. Then when (on that second page) you click done, you return to the first page. On this first page I'd like to create a tablesubview where I can have stored the information both from the textfield on the first page and the options on the second page. Here is the method code...

#import "EnteringCoursesViewController.h"
#import "SelectRotationController.h"


@implementation EnteringCoursesViewController

@synthesize classField;
@synthesize indicatedClass;
@synthesize labelClassTitle;
@synthesize selectRotationController;
@synthesize classesEntered;


- (IBAction)chooseType {
    UIActionSheet *typeSheet = [[UIActionSheet alloc]
                                initWithTitle:@"Class types"
                                delegate:self
                                cancelButtonTitle:nil
                                destructiveButtonTitle:nil
                                otherButtonTitles:@"Core Class", @"Elective", nil];
    [typeSheet showInView:self.view];
    [typeSheet release];
}   

- (void)actionSheet:(UIActionSheet *)typeSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 0) {
        self.indicatedClass = classField.text;
        NSString *indicatedString = indicatedClass;
        NSString *greeting = [[NSString alloc] 
                              initWithFormat:@"%@ meets 6 times per rotation", indicatedString];
        labelClassTitle.text = greeting;
        labelClassTitle.hidden = NO;
        [greeting release];
        [indicatedClass release];
    }
    else if (buttonIndex == 1) {
        self.indicatedClass = classField.text;
        NSString *indicatedString = indicatedClass;
        NSString *greeting = [[NSString alloc] 
                              initWithFormat:@"%@ meets 3 times per rotation", indicatedString];
        labelClassTitle.text = greeting;
        labelClassTitle.hidden = NO;
        [greeting release];
        [indicatedClass release];
    } 

}

- (IBAction)chooseFirstMeeting:(id)sender {     
    SelectRotationController *selectView = [[SelectRotationController alloc] 
                                                 initWithNibName:@"SelectRotationController"
                                                 bundle:[NSBundle mainBundle]];
    [selectView.navigationItem setTitle:@"First Period Day Choose"];

    [self.navigationController pushViewController:self.selectRotationController animated:YES];
    self.selectRotationController = selectView; 
    [selectView release];
}

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc. that aren't in use.
}

- (void)viewDidLoad {
    NSMutableArray *array = [[NSMutableArray alloc]
                        //help here!//
    self.classesEntered = array;
    [array release]; 

    self.navigationItem.hidesBackButton = YES;
    [super viewDidLoad];

}
- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [classField release];
    [labelClassTitle release];
    [indicatedClass release];
    [selectRotationController release];
    [classesEntered release];
    [super dealloc];
}


@end

Upvotes: 0

Views: 345

Answers (1)

fishinear
fishinear

Reputation: 6336

If I understand your problem correctly, then the following would be good approach:

In the first controller, create a model object that hold all the information of both input pages. Before you push the second controller, set a property of it to the model object. The second controller then populates the model object with user information.

The model object can be a class of your own, it can be as simple as an NSMutableArray, or it could even be the first view controller itself.

Upvotes: 1

Related Questions