【发布时间】:2015-05-04 13:40:02
【问题描述】:
我创建了一个横向显示的表格视图。
我想向表格单元格动态添加多个文本字段,并且还想获取数据,任何人都可以建议我。如何在 iOS 中水平滚动?
【问题讨论】:
标签: ios uitableview dynamic uiscrollview
我创建了一个横向显示的表格视图。
我想向表格单元格动态添加多个文本字段,并且还想获取数据,任何人都可以建议我。如何在 iOS 中水平滚动?
【问题讨论】:
标签: ios uitableview dynamic uiscrollview
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;
}
【讨论】:
您可以先在 tableCell 上添加一个滚动视图,而不是在此滚动视图上添加多个 textField,而不是直接将 textField 添加到 tableCell 中。相应地设置滚动视图的内容大小,以便它可以轻松滚动到最后。
【讨论】: