私は今、何日UITextFields
もセクションのセルの入力を設定して取得しようとしています。
私の最初のビューUITextField
では、必要なセクションの数を指定する場所に移動し、ボタンを押すと、そのセクション (4 行) がUITableView
. 私の問題は、 each の正しい値を取得できないことです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 を正しい行に置き換えるにはどうすればよいですか?