- (IBAction)namePoints:(id)sender {
yValuePoints = 180;
pointTextBoxCounter = 0;
while (numberOfPointsTextBox.text.intValue > currentPointTextBox) {
CGRect textFrame = CGRectMake(245, yValuePoints, 60, 30);
UITextField *textField = [[UITextField alloc] initWithFrame:textFrame];
[textField setBackgroundColor:[UIColor whiteColor]];
[textField setBorderStyle:UITextBorderStyleRoundedRect];
textField.textAlignment = UITextAlignmentRight;
[self.view addSubview:textField];
currentPointTextBox += 1;
yValuePoints += 40;
if (yValuePoints > mainScrollView.contentSize.height) {
[mainScrollView setContentSize:CGSizeMake(320, (yValuePoints + 20))];
}
}
while (numberOfPointsTextBox.text.intValue < currentPointTextBox) {
[self.view.subviews.lastObject removeFromSuperview];
//[[pointsTextFieldsArray objectAtIndex:currentPointTextBox] removeFromSuperview];
currentPointTextBox -= 1;
}
}
This function is called when numberOfPointsTextBox didFinishEditing. CurrentPointTextBox is an int that (hopefully) keeps track of the number of point text boxes currently on the screen (there others such as planes with a similar function). What I would like is when the value of numberOfPointsTextBox is decreased for the extra point text boxes to be removed. What I have been trying to do is use pointsTextFieldsArray to keep track of the index values of the fields that I have created in the self.view.subviews array so that I can just run the commented out line of code, but NSMutableArray’s won’t accept int values and I can’t find a way find to dynamically create NSIntegers. Does anyone know how to do this? Or a better way to do it?
I belive your approach is not quite right. You should update your view every time the
currentPointTextBoxis changed.That said, You’d need to, on your init function, set it to
0(zero), and go from there.I’m assuming you’re always removing the last ones or adding on the end of the “list”. This way, you could store the TextFields in the pointsTextFieldsArray wich should be an
NSMutableArrayobject.I’ve put together some code (based on yours) that should point you in the right direction:
Bug me a little more if you need more help.