Как заполнить NSMutableArray с введенным текстовым полем - PullRequest
0 голосов
/ 15 февраля 2012

Проблема, с которой я сталкиваюсь, заключается в том, что после того, как я ввожу текст в текстовое поле, мне нужно покинуть страницу и перейти к определенным параметрам. Затем, когда (на этой второй странице) вы нажмете «Готово», вы вернетесь на первую страницу. На этой первой странице я хотел бы создать представление таблицы, где я мог бы хранить информацию и из текстового поля на первой странице и опций на второй странице. Вот код метода ...

#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

1 Ответ

1 голос
/ 15 февраля 2012

Если я правильно понимаю вашу проблему, то следующим подходом будет:

В первом контроллере создайте объект модели, который содержит всю информацию обеих входных страниц. Прежде чем нажать на второй контроллер, установите его свойство для объекта модели. Затем второй контроллер заполняет объект модели информацией о пользователе.

Объект модели может быть вашим собственным классом, он может быть таким же простым, как NSMutableArray, или это может быть даже первый контроллер представления.

...