지금 섹션을 설정하고 입력란에 UITextFields
의 입력을 가져 오려고 노력하고 있습니다.UITextFields가있는 UITableView 섹션
내 첫 번째보기에서 나는 얼마나 많은 섹션을 갖고 싶은지, 그리고 버튼을 누를 때 UITableView
에있는 해당 섹션 (4 행)을 제공하는 UITextField
을 가지고 있습니다. 지금 내 문제는 각각 UITextField
의 올바른 값을 얻지 못한다는 것입니다. 예를 들어
:
- 모든 섹션은 INT를 작성하거나 내가 텍스트 필드 1과 2에서 INT를 알고
- 떠있는 텍스트 필드에
- 4 텍스트 필드에 있고, 나는 그들을 분할 ... 여기
내 코드는 ....
#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를 어떻게 바꿀 수 있습니까? ,
이NSMutableArray *tableViewData = [NSMutableArray array];
[tableViewData addObject:@[ @{@"textfield" : YourTextField} ]];
[tableViewData addObject:@[ @{@"textfield" : YourTextField} ]];
[tableViewData addObject:@[ @{@"textfield" : YourTextField} ]];
[tableViewData addObject:@[ @{@"textfield" : YourTextField} ]];
위의 코드는 4 개 배열을 포함, tableViewData
나타내는 각 배열은 단일 셀의 데이터를 유지 한 사전을 포함
이상적으로 데이터 소스 콜백에서 데이터 소스에 개체를 추가해서는 안됩니다. 왜 viewDidLoad에서 그렇게하지 않습니까? 귀하의 질문은 당신이 무엇을 요구하고 있는지 이해하기가 어렵습니다. – Tim
그래서 먼저 viewdidload에 섹션을 추가해야합니까? – user2912794
다른 섹션 데이터를 다른 곳에 만들면 위임 콜백이 그 방식으로 카운트를 검색 할 수 있습니다. 귀하의 실제 질문의 측면에서, 난 아직도 이해가 안 돼 – Tim