我正在通過按鈕操作在數組中逐個添加textfields,同樣我想從另一個按鈕中刪除這些文本字段,我應該怎麼做我正在使用此代碼添加從nsmutable陣列中刪除對象
- (IBAction)btnAddTxtField:(id)sender {
// [self buttonPressed];
// currentIndex =0;
//
// int x = 132;
// int y = 550;
//
//
// UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake((currentIndex % 1) * x + 45, (currentIndex/1) * y + 28, 214, 25)];
//
//
textField = [[UITextField alloc] initWithFrame:CGRectMake(76, ([txtFieldArray count] * 30), 191, 25)];
[textField setBorderStyle:UITextBorderStyleLine];
textField.font = [UIFont systemFontOfSize:20];
textField.placeholder = @"Enter text";
textField.autocorrectionType = UITextAutocorrectionTypeNo;
textField.keyboardType = UIKeyboardTypeDefault;
textField.returnKeyType = UIReturnKeyDone;
textField.clearButtonMode = UITextFieldViewModeWhileEditing;
textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
textField.delegate = self;
[myScrollview addSubview:textField];
[txtFieldArray addObject:textField];
CGRect frame = bottomView.frame;
frame.origin.y += textField.frame.size.height + 5;
bottomView.frame = frame;
textField.hidden = NO;
}
和去除
- (IBAction)btnRemovTxtField:(id)sender {
[txtFieldArray removeLastObject];
textField.hidden = YES;
CGRect frame = bottomView.frame;
frame.origin.y -= textField.frame.size.height - 5;
bottomView.frame = frame;
}
我只是想刪除文本框一個接一個,任何幫助,請
因此,您正在通過'removeLastObject'刪除,那麼問題是什麼呢? – 2013-04-11 06:43:27
它不是刪除 – NullData 2013-04-11 06:43:44
我想刪除最後一個對象,如果按下按鈕,然後再次按下按鈕,直到數組計數爲零或用戶停止按下按鈕 – NullData 2013-04-11 06:44:46