我有一个方法应该将输入到文本字段中的内容保存为字符串(稍后将保存到NSMutableArray中),然后在退出文本字段后调出一个操作表,该字段将进一步指定字符串,具体取决于哪个单击按钮。请帮忙!我在高中时试图为我的高级项目编写程序,所以任何帮助都非常感谢!谢谢!
@implementation EnteringCoursesViewController
@synthesize classField;
@synthesize indicatedClass;
@synthesize labelClassTitle;
@synthesize selectRotationController;
@synthesize classesEnteredTable;
- (IBAction)classFieldDoneEditing:(id)sender
withActionSheet:(UIActionSheet *)typeSheet
clickedButtonAtIndex:(NSInteger)buttonIndex
{
self.indicatedClass = classField.text;
NSString *greeting = [[NSString alloc]
initWithFormat:@"%@", indicatedClass];
labelClassTitle.text = greeting;
labelClassTitle.hidden = NO;
[greeting release];
[sender resignFirstResponder];
typeSheet = [[UIActionSheet alloc]
initWithTitle:@"Class types"delegate:self
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:@"Core Class", @"Elective", nil];
[typeSheet showInView:self.view];
[typeSheet release];
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];
}
}
对理论方法的评论很有帮助,但由于我对此很陌生,所以我非常喜欢特定的编码感谢。
@interface EnteringCoursesViewController : UIViewController {
UILabel *labelClassTitle;
NSString *indicatedClass;
UITextField *classField;
UIViewController *selectRotationController;
UITableView *classesEnteredTable;
}
@property (nonatomic, retain) IBOutlet UILabel *labelClassTitle;
@property (nonatomic, copy) NSString *indicatedClass;
@property (nonatomic, retain) IBOutlet UITextField *classField;
@property (nonatomic, retain) UIViewController *selectRotationController;
@property (nonatomic, retain) IBOutlet UITableView *classesEnteredTable;
- (IBAction)chooseFirstMeeting:(id)sender;
- (IBAction)classFieldDoneEditing:(id)sender withActionSheet:(UIActionSheet *)typeSheet
clickedButtonAtIndex:(NSInteger)buttonIndex;
答案 0 :(得分:0)
您可以通过向与按钮连接的操作添加多个参数,将方法迁移到一个方法。代码应该是这样的:
- (IBAction)cassFieldDoneEditing:(id)sender
withActionSheet:(UIActionSheet *)typeSheet
clickedButtonAtIndex:(NSInteger)buttonIndex
{
self.indicatedClass = classField.text;
NSString *greeting = [[NSString alloc]
initWithFormat:@"%@", indicatedClass];
labelClassTitle.text = greeting;
labelClassTitle.hidden = NO;
[greeting release];
[sender resignFirstResponder];
UIActionSheet *typeSheet = [[UIActionSheet alloc]
initWithTitle:@"Class types"delegate:self
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:@"Core Class", @"Elective", nil];
[typeSheet showInView:self.view];
[typeSheet release];
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];
}
[theSmallArray addObject:indicatedClass];
}
由于我没有测试过代码,因此可能存在错误。如果你有任何问题,请报告回来吗?