我现在正在尝试很多天来设置和获取UITextFields
部分单元格的输入。
在我的第一个视图UITextField
中,我说我想要有多少个部分,当按下一个按钮时,它会给我在UITableView
. 我现在的问题是,我没有得到每个UITextField
.
例如:
- 所有部分都有 4 个文本字段
- 在文本字段中可以写 int 或 float
- 当我知道文本字段 1 和 2 的 int 时,我将它们分开......
这是我的代码....
#import "ViewController.h"
@interface ViewController ()
{
NSMutableArray *sectionsArray;
NSMutableArray *rowsArray;
NSMutableArray *textFieldArray;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib.
[[self myTableView]setDelegate:self];
[[self myTableView]setDataSource:self];
sectionsArray = [[NSMutableArray alloc]init];
rowsArray = [[NSMutableArray alloc]initWithObjects:@"",@"",@"",@"", nil];
textFieldArray = [[NSMutableArray alloc]initWithObjects:@"",@"",@"",@"", nil];
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.myTableView reloadData];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table View
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
int anzahl = [_AnzahlStationen intValue];//from first view...anzahl=quantity of sections
//adds sections
do {
[sectionsArray addObject:[NSString stringWithFormat:@"Palette %lu",sectionsArray.count+1]];
} while ([sectionsArray count] < anzahl);
return sectionsArray.count;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return rowsArray.count;
}
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return [sectionsArray objectAtIndex:section];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
if (cell==nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(10, 10, 300, 24)];
textField.font = [UIFont fontWithName:@"Gujarati Sangam MN" size:15];
textField.textColor = [UIColor redColor];
textField.autoresizingMask = UIViewAutoresizingFlexibleWidth;
textField.tag = 17;
[cell.contentView addSubview:textField];
textField.delegate = self;
}
UITextField *textField = (UITextField *)[cell.contentView viewWithTag:17];
textField.text = [textFieldArray objectAtIndex:indexPath.row];
return cell;
}
#pragma mark - UITextFieldDelegate
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
return YES;
}
- (void)textFieldDidEndEditing:(UITextField *)textField {
[textFieldArray replaceObjectAtIndex:0 withObject:textField.text];
}
@end
如何在正确的行中替换正确的 UITextField?