I have a UITableView some UITextField on Table view cell. UITextFields in user enter some values on the text field and then scrolling table view.the value on text field is not persist. below code
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 100;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
static NSString *CellIdentifierFirst = @"CellFirst";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifierFirst];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:CellIdentifier] autorelease];
}
NSArray *cellSubs = cell.contentView.subviews;
for (int i = 0 ; i < [cellSubs count] ; i++) {
[[cellSubs objectAtIndex:i] removeFromSuperview];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
UITextField * textFieldRounded = [[UITextField alloc] initWithFrame:CGRectMake(100, 5, 150, 40)];
textFieldRounded.borderStyle = UITextBorderStyleNone;
textFieldRounded.textColor = [UIColor blackColor];
textFieldRounded.font = [UIFont systemFontOfSize:17.0];
textFieldRounded.placeholder = @"Type here";
textFieldRounded.backgroundColor = [UIColor whiteColor];
textFieldRounded.autocorrectionType = UITextAutocorrectionTypeNo;
textFieldRounded.keyboardType = UIKeyboardTypeDefault;
textFieldRounded.returnKeyType = UIReturnKeyDone;
textFieldRounded.clearButtonMode = UITextFieldViewModeWhileEditing;
textFieldRounded.delegate = self;
[cell.contentView addSubview:textFieldRounded];
return cell;
}
So Please help me everyone
You will need to maintain a mutable array for all the rows. You will have to store the text in that array every time the text is changed and set the text from the array when
cellForRowAtIndexPath:is called.