Note that there are some explanatory texts on larger screens.

plurals
  1. POUITableview with textfields to arrays
    primarykey
    data
    text
    <p>I'm not sure if I am approaching this the correct way so I need some help. I have a table with 5 rows for data to be entered. After the user enters all the data there is a button on the navigation bar that will add the data to the arrays. I want to set up another view controller that displays all of the data that has been entered by the user. I hope this makes sense. Here's what I have so far. </p> <pre><code>- (void)viewDidLoad { [super viewDidLoad]; [self initWithStyle: UITableViewStyleGrouped]; self.navigationController.navigationBarHidden=NO; //self.navigationItem.hidesBackButton = YES; // Uncomment the following line to preserve selection between presentations. //self.clearsSelectionOnViewWillAppear = NO; // Uncomment the following line to display an Edit button in the navigation bar for this view controller. self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle: @"Done" style:UIBarButtonItemStylePlain target: self action: @selector(add)] autorelease]; course = [[NSMutableArray alloc] init]; date = [[NSMutableArray alloc] init]; scores = [[NSMutableArray alloc] init]; rating = [[NSMutableArray alloc] init]; slope = [[NSMutableArray alloc] init]; } - (void)viewDidUnload { [super viewDidUnload]; // Release any retained subviews of the main view. // e.g. self.myOutlet = nil; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; } - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; } - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; } - (void)viewDidDisappear:(BOOL)animated { [super viewDidDisappear:animated]; } #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 5; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; cell.accessoryType = UITableViewCellAccessoryNone; if ([indexPath section] == 0) { if ([indexPath row] == 0) { UITextField *playerTextField = [[UITextField alloc] initWithFrame:CGRectMake(110, 10, 185, 30)]; playerTextField.adjustsFontSizeToFitWidth = YES; playerTextField.textColor = [UIColor blackColor]; playerTextField.placeholder = @"Required"; playerTextField.keyboardType = UIKeyboardTypeDefault; playerTextField.returnKeyType = UIReturnKeyNext; playerTextField.text = [course objectAtIndex:indexPath.row]; playerTextField.backgroundColor = [UIColor whiteColor]; playerTextField.textAlignment = UITextAlignmentRight; [playerTextField setEnabled: YES]; [cell addSubview:playerTextField]; [playerTextField release]; } else if([indexPath row] == 1){ UITextField *playerTextField = [[UITextField alloc] initWithFrame:CGRectMake(110, 10, 185, 30)]; playerTextField.adjustsFontSizeToFitWidth = YES; playerTextField.textColor = [UIColor blackColor]; playerTextField.placeholder = @"Required"; playerTextField.keyboardType = UIKeyboardTypeNumbersAndPunctuation; playerTextField.returnKeyType = UIReturnKeyDone; playerTextField.text = [date objectAtIndex:indexPath.row]; playerTextField.backgroundColor = [UIColor whiteColor]; playerTextField.textAlignment = UITextAlignmentRight; [playerTextField setEnabled: YES]; [cell addSubview:playerTextField]; [playerTextField release]; } else if([indexPath row] == 2){ UITextField *playerTextField = [[UITextField alloc] initWithFrame:CGRectMake(110, 10, 185, 30)]; playerTextField.adjustsFontSizeToFitWidth = YES; playerTextField.textColor = [UIColor blackColor]; playerTextField.placeholder = @"Required"; playerTextField.keyboardType = UIKeyboardTypeNumberPad; playerTextField.returnKeyType = UIReturnKeyDone; playerTextField.text = [scores objectAtIndex:indexPath.row]; playerTextField.backgroundColor = [UIColor whiteColor]; playerTextField.textAlignment = UITextAlignmentRight; [playerTextField setEnabled: YES]; [cell addSubview:playerTextField]; [playerTextField release]; } else if([indexPath row] == 3){ UITextField *playerTextField = [[UITextField alloc] initWithFrame:CGRectMake(110, 10, 185, 30)]; playerTextField.adjustsFontSizeToFitWidth = YES; playerTextField.textColor = [UIColor blackColor]; playerTextField.placeholder = @"Required"; playerTextField.keyboardType = UIKeyboardTypeNumbersAndPunctuation; playerTextField.returnKeyType = UIReturnKeyDone; playerTextField.text = [rating objectAtIndex:indexPath.row]; playerTextField.backgroundColor = [UIColor whiteColor]; playerTextField.textAlignment = UITextAlignmentRight; [playerTextField setEnabled: YES]; [cell addSubview:playerTextField]; [playerTextField release]; } else if([indexPath row] == 4){ UITextField *playerTextField = [[UITextField alloc] initWithFrame:CGRectMake(110, 10, 185, 30)]; playerTextField.adjustsFontSizeToFitWidth = YES; playerTextField.textColor = [UIColor blackColor]; playerTextField.placeholder = @"Required"; playerTextField.keyboardType = UIKeyboardTypeNumbersAndPunctuation; playerTextField.returnKeyType = UIReturnKeyDone; playerTextField.text = [slope objectAtIndex:indexPath.row]; playerTextField.backgroundColor = [UIColor whiteColor]; playerTextField.textAlignment = UITextAlignmentRight; [playerTextField setEnabled: YES]; [cell addSubview:playerTextField]; [playerTextField release]; } } } if ([indexPath section] == 0) { if ([indexPath row] == 0) { cell.textLabel.text = @"Course"; } else if([indexPath row] == 1){ cell.textLabel.text = @"Date"; } else if([indexPath row] == 2){ cell.textLabel.text = @"Score"; } else if([indexPath row] == 3){ cell.textLabel.text = @"Rating"; } else if([indexPath row] == 4){ cell.textLabel.text = @"Slope"; } } return cell; } - (BOOL)textFieldShouldEndEditing:(UITextField *)textField { [course replaceObjectAtIndex:textField.tag withObject:textField.text]; [date replaceObjectAtIndex:textField.tag withObject:textField.text]; [scores replaceObjectAtIndex:textField.tag withObject:textField.text]; [rating replaceObjectAtIndex:textField.tag withObject:textField.text]; [slope replaceObjectAtIndex:textField.tag withObject:textField.text]; return YES; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload