所以我需要在保存到nsmutablearray的文本字段中輸入任何內容(這必須發生多次!每次必須另存爲另一個對象) 。但是無論我明確表達什麼都行不通,因爲它說「文本」不在結構或聯盟中。繼承人我的代碼。感謝您的任何意見!你如何引用一個文本字段並將其輸入到一個可變數組中
問題出在enteredClassText方法中。
#import "EnteringCoursesViewController.h"
#import "SelectRotationController.h"
@implementation EnteringCoursesViewController
@synthesize classField;
@synthesize indicatedClass;
@synthesize labelClassTitle;
@synthesize selectRotationController;
@synthesize classesEnteredTable;
- (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];
}
- (IBAction)enteredClassText:(id)sender {
NSMutableArray *classesEntered = [NSMutableArray arrayWithObject:sender.text];
[classesEntered = [NSMutableArray alloc] init];
[classesEntered release];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (void)viewDidLoad {
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];
[classesEnteredTable release];
[super dealloc];
}
@end
不應該是:'[theArray addObject:theStringToAdd];'? – 2012-02-29 19:55:55
對不起,代碼已被編輯! – wizH 2012-02-29 19:59:20
如果你想關閉鍵盤,不要忘記[textField resignFirstResponder]。 – 2012-02-29 20:25:21