我创建了一个以横向显示的表格视图。
我想动态地向表格单元格添加多个文本字段,并希望获得任何人建议的数据。如何在iOS中水平滚动?
答案 0 :(得分:0)
UITextField *mytextField = [[UITextField alloc]initWithFrame:CGRectMake(110, 10, 185, 30)];
mytextField.clearsOnBeginEditing = NO;
mytextField.textAlignment = UITextAlignmentRight;
mytextField.delegate = self;
[yourCell.contentView addSubview: mytextField];
或
试试这个
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
if (indexPath.row == 0){
21)];
self.mytextField1 = [[UITextField alloc] initWithFrame:CGRectMake(120, 13, 375, 30)];
self.mytextField1.placeholder = @"mytextField1";
self.mytextField1.autocorrectionType = UITextAutocorrectionTypeNo;
[self.mytextField1 setClearButtonMode:UITextFieldViewModeWhileEditing];
[cell addSubview:self.mytextField1];
}
if (indexPath.row == 1){
self.mytextField2 = [[UITextField alloc] initWithFrame:CGRectMake(120, 13, 375, 30)];
self.mytextField2.placeholder = @"mytextField2";
self.mytextField2.autocorrectionType = UITextAutocorrectionTypeNo;
[self.mytextField2 setClearButtonMode:UITextFieldViewModeWhileEditing];
[cell addSubview:self.mytextField2];
}
if (indexPath.row == 2){
// add here
}
if (indexPath.row == 3){
}
self.mytextField1.delegate = self;
self.mytextField2.delegate = self;
// and other also here
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
答案 1 :(得分:0)
除了将textField直接添加到tableCell之外,您可以先在tableCell上添加滚动视图,而不是在此滚动视图上添加多个textField。相应地设置滚动视图的内容大小,以便它可以轻松滚动到最后。