我试图了解创建这样的东西的最佳方法:
我想知道如何克隆 UIView 并从上面的 UITextView 中检索每个数据。 我这里使用storyboard,可以通过添加容器 View 来完成吗?
谢谢!
更新
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
[tableView registerClass: [TitleCell class] forCellReuseIdentifier:@"Title"];
TitleCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Title" forIndexPath:indexPath];
switch (indexPath.row) {
case 0:
cell.leftLabel.text = @"Title";
//cell.labelRight.text = self.theData[indexPath.section][@"Title"];
break;
case 1:
cell.leftLabel.text = @"FirstName";
//cell.labelRight.text = self.theData[indexPath.section][@"FirstName"];
break;
case 2:
cell.leftLabel.text = @"LastName";
//cell.labelRight.text = self.theData[indexPath.section][@"LastName"];
break;
default:
break;
}
return cell;
}
现在没有返回错误,但奇怪的是它没有显示 leftLabel 文本。
是的,我正在使用 Storyboard。
最佳答案
实现这一点的最佳方法是使用 UITableView,您不需要“克隆”任何内容。您发布的图像看起来像一个包含多个部分的表格 View ,每个部分有 5 行。每个单元格都有两个标签,左侧一个带有固定文本,右侧一个带有您将从数据源填充的数据。下面是每个部分有 3 行的示例。数据源是一个包含键、Title、FirstName 和 LastName 的字典数组。
self.theData = @[@{@"Title":@"Mr",@"FirstName":@"Joe",@"LastName":@"Montana"},@{@"Title":@"Dr",@"FirstName":@"Julius",@"LastName":@"Irving"},@{@"Title":@"Mr",@"FirstName":@"Alex",@"LastName":@"Smith"}];
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
RDCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
switch (indexPath.row) {
case 0:
cell.labelLeft.text = @"Title";
cell.labelRight.text = self.theData[indexPath.section][@"Title"];
break;
case 1:
cell.labelLeft.text = @"FirstName";
cell.labelRight.text = self.theData[indexPath.section][@"FirstName"];
break;
case 2:
cell.labelLeft.text = @"LastName";
cell.labelRight.text = self.theData[indexPath.section][@"LastName"];
break;
default:
break;
}
return cell;
}
关于ios - 如何从其中包含许多 UITextview 的 UIView 复制和检索数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20027141/