我有一個UITableView
一些UITextField
上表視圖單元格。 UITextField
s在用戶輸入文本字段的一些值,然後滾動表視圖。文本字段上的值不會持續。下面的代碼滾動文本字段值表格視圖不會持續
- (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;
}
所以請大家幫幫我大家
你在哪裏添加文本字段? –