我遇到的问题是,在我将文本输入文本字段后,我必须离开页面并继续选择某些选项。然后当(在第二页上)单击完成后,您将返回第一页。在第一页上,我想创建一个tablesubview,我可以在第一页的文本字段和第二页的选项中存储两者的信息。这是方法代码......
#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
答案 0 :(得分:1)
如果我理解你的问题,那么以下是好方法:
在第一个控制器中,创建一个模型对象,其中包含两个输入页面的所有信息。在推送第二个控制器之前,请将其属性设置为模型对象。然后,第二个控制器使用用户信息填充模型对象。
模型对象可以是您自己的类,它可以像NSMutableArray一样简单,也可以是第一个视图控制器本身。