我是 XCODE 的新手,但我正在努力学习。基本上,我的项目是 Nada Jaksic 的在 iPhone 上创建基于表格的表单的返工。我希望能被告知我在编码中出错的地方,以便我可以从错误中吸取教训。任何和所有的帮助都非常感谢!
从 SignupTableViewController.h 文件中:
#import <UIKit/UIKit.h>
@interface SignupTableViewController : UITableViewController<UITextFieldDelegate, UIActionSheetDelegate>
{
IBOutlet UITableViewCell *cellExaminername;
IBOutlet UITableViewCell *cellExamineraddress;
IBOutlet UITableViewCell *cellExaminercity;
IBOutlet UITableViewCell *cellExaminerstate;
IBOutlet UITableViewCell *cellExaminerzip;
IBOutlet UITableViewCell *cellExamineremail;
IBOutlet UITableViewCell *cellSearchthroughdate;
IBOutlet UITableViewCell *cellTitleheldby;
IBOutlet UITableViewCell *cellPropertyaddress1;
IBOutlet UITableViewCell *cellPropertyaddress2;
IBOutlet UITableViewCell *cellPropertycity;
IBOutlet UITableViewCell *cellPropertystate;
IBOutlet UITableViewCell *cellProperyzip;
IBOutlet UITableViewCell *cellTitlesearchnotes;
IBOutlet UITextField* txtExaminername;
IBOutlet UITextField* txtExamineraddress;
IBOutlet UITextField* txtExaminercity;
IBOutlet UITextField* txtExaminerstate;
IBOutlet UITextField* txtExaminerzip;
IBOutlet UITextField* txtExamineremail;
IBOutlet UITextField* txtSearchthroughdate;
IBOutlet UITextField* txtTitleheldby;
IBOutlet UITextField* txtPropertyaddress1;
IBOutlet UITextField* txtPropertyaddress2;
IBOutlet UITextField* txtPropertycity;
IBOutlet UITextField* txtPropertystate;
IBOutlet UITextField* txtPropertyzip;
IBOutlet UITextField* txtTitlesearchnotes;
UIActivityIndicatorView* activityIndicator;
}
@property (nonatomic, retain) IBOutlet UITableViewCell *cellExaminername;
@property (nonatomic, retain) IBOutlet UITableViewCell *cellExamineraddress;
@property (nonatomic, retain) IBOutlet UITableViewCell *cellExaminercity;
@property (nonatomic, retain) IBOutlet UITableViewCell *cellExaminerstate;
@property (nonatomic, retain) IBOutlet UITableViewCell *cellExaminerzip;
@property (nonatomic, retain) IBOutlet UITableViewCell *cellExamineremail;
@property (nonatomic, retain) IBOutlet UITableViewCell *cellSearchthroughdate;
@property (nonatomic, retain) IBOutlet UITableViewCell *cellTitleheldby;
@property (nonatomic, retain) IBOutlet UITableViewCell *cellPropertyaddress1;
@property (nonatomic, retain) IBOutlet UITableViewCell *cellPropertyaddress2;
@property (nonatomic, retain) IBOutlet UITableViewCell *cellPropertycity;
@property (nonatomic, retain) IBOutlet UITableViewCell *cellPropertystate;
@property (nonatomic, retain) IBOutlet UITableViewCell *cellProperyzip;
@property (nonatomic, retain) IBOutlet UITableViewCell *cellTitlesearchnotes;
@property (nonatomic, retain) IBOutlet UITextField* txtExaminername;
@property (nonatomic, retain) IBOutlet UITextField* txtExamineraddress;
@property (nonatomic, retain) IBOutlet UITextField* txtExaminercity;
@property (nonatomic, retain) IBOutlet UITextField* txtExaminerstate;
@property (nonatomic, retain) IBOutlet UITextField* txtExaminerzip;
@property (nonatomic, retain) IBOutlet UITextField* txtExamineremail;
@property (nonatomic, retain) IBOutlet UITextField* txtSearchthroughdate;
@property (nonatomic, retain) IBOutlet UITextField* txtTitleheldby;
@property (nonatomic, retain) IBOutlet UITextField* txtPropertyaddress1;
@property (nonatomic, retain) IBOutlet UITextField* txtPropertyaddress2;
@property (nonatomic, retain) IBOutlet UITextField* txtPropertycity;
@property (nonatomic, retain) IBOutlet UITextField* txtPropertystate;
@property (nonatomic, retain) IBOutlet UITextField* txtPropertyzip;
@property (nonatomic, retain) IBOutlet UITextField* txtTitlesearchnotes;
-(void)signup;
@end
从我的 SignupTableViewController.m 文件中:
#import "SignupTableViewController.h"
@implementation SignupTableViewController
@synthesize cellExaminername, cellExamineraddress, cellExaminercity, cellExaminerstate, cellExaminerzip, cellExamineremail, cellSearchthroughdate, cellTitleheldby, cellPropertyaddress1, cellPropertyaddress2, cellPropertycity, cellPropertystate, cellProperyzip, cellTitlesearchnotes;
@synthesize txtExaminername, txtExamineraddress, txtExaminercity, txtExaminerstate, txtExaminerzip, txtExamineremail, txtSearchthroughdate, txtTitleheldby, txtPropertyaddress1, txtPropertyaddress2, txtPropertycity, txtPropertystate, txtPropertyzip, txtTitlesearchnotes;
#pragma mark -
#pragma mark View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
// Uncomment the following line to preserve selection between presentations.
//self.clearsSelectionOnViewWillAppear = NO;
UIBarButtonItem* btnSubmitSignup = [[UIBarButtonItem alloc]initWithTitle:NSLocalizedString(@"Join",@"") style:UIBarButtonItemStylePlain target:self action:@selector(signup)];
[[self navigationItem] setRightBarButtonItem:btnSubmitSignup];
}
#pragma mark -
#pragma mark Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
return 14;
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row == 0) {
return cellExaminername;
}
if (indexPath.row == 1) {
return cellExamineraddress;
}
if (indexPath.row == 2) {
return cellExaminercity;
}
if (indexPath.row == 3) {
return cellExaminerstate;
}
if (indexPath.row == 4) {
return cellExaminerzip;
}
if (indexPath.row == 5) {
return cellExamineremail;
}
if (indexPath.row == 6) {
return cellSearchthroughdate;
}
if (indexPath.row == 7) {
return cellTitleheldby;
}
if (indexPath.row == 8) {
return cellPropertyaddress1;
}
if (indexPath.row == 9) {
return cellPropertyaddress2;
}
if (indexPath.row == 10) {
return cellPropertycity;
}
if (indexPath.row == 11) {
return cellPropertystate;
}
if (indexPath.row == 12) {
return cellProperyzip;
}
if (indexPath.row == 13) {
return cellTitlesearchnotes;
}
}
#pragma mark -
#pragma mark Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Navigation logic may go here. Create and push another view controller.
/*
<#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
// ...
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
*/
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}
- (void)textFieldDidBeginEditing:(UITextField *)textField
#pragma mark -
#pragma mark Memory management
-(void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Relinquish ownership any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Relinquish ownership of anything that can be recreated in viewDidLoad or on demand.
// For example: self.myOutlet = nil;
}
-(void) signup
{
// make sure the keyboard is hidden
[txtExaminername resignFirstResponder];
[txtExamineraddress resignFirstResponder];
[txtExaminercity resignFirstResponder];
[txtExaminerstate resignFirstResponder];
[txtExaminerzip resignFirstResponder];
[txtExamineremail resignFirstResponder];
[txtSearchthroughdate resignFirstResponder];
[txtTitleheldby resignFirstResponder];
[txtPropertyaddress1 resignFirstResponder];
[txtPropertyaddress2 resignFirstResponder];
[txtPropertycity resignFirstResponder];
[txtPropertystate resignFirstResponder];
[txtPropertyzip resignFirstResponder];
[txtTitlesearchnotes resignFirstResponder];
activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
[activityIndicator setCenter:CGPointMake(self.view.frame.size.width/2.0, self.view.frame.size.height/2.0+20)];
[activityIndicator startAnimating];
[self.view addSubview:activityIndicator];
if (![self validateSignupForm])
return;
//do your signup code here
}
-(BOOL)validateSignupForm
{
BOOL rtn = YES;
// Declare your Alert, NSArray, increment int
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:NSLocalizedString(@"FormIncomplete", @"") delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
NSArray *fieldArray;
int i = 0;
// Load up our field array with the UITextField Values
fieldArray = [NSArray arrayWithObjects:
[NSString stringWithFormat:@"%@",txtExaminername.text],
[NSString stringWithFormat:@"%@",txtExamineraddress.text],
[NSString stringWithFormat:@"%@",txtExaminercity.text],
[NSString stringWithFormat:@"%@",txtExaminerstate.text],
[NSString stringWithFormat:@"%@",txtExaminerzip.text],
[NSString stringWithFormat:@"%@",txtExamineremail],
[NSString stringWithFormat:@"%@",txtSearchthroughdate.text],
[NSString stringWithFormat:@"%@",txtTitleheldby.text],
[NSString stringWithFormat:@"%@",txtPropertyaddress1.text],
[NSString stringWithFormat:@"%@",txtPropertyaddress2.text],
[NSString stringWithFormat:@"%@",txtPropertycity.text],
[NSString stringWithFormat:@"%@",txtPropertystate.text],
[NSString stringWithFormat:@"%@",txtPropertyzip.text],
[NSString stringWithFormat:@"%@",txtTitlesearchnotes.text]];
// loop through the array, alert if text field is empty, and break the the loop, other wise increment i
for (NSString *fieldText in fieldArray){
NSLog(fieldText); // make sure all is reading correctly in the console
if([fieldText isEqualToString:@""]){
[alert show];
rtn = NO;
break; // break out!!
}
i++;
}
// check that all the field were passed (i == array.count)
//if(i == [[NSNumber numberWithInt: fieldArray.count] intValue]){
//NSLog(@"Passed validation...");
//rtn = YES;
// {
//if (rtn)
@end