ios - 如何从其中包含许多 UITextview 的 UIView 复制和检索数据

标签 ios uiview clone

我试图了解创建这样的东西的最佳方法:

UIViews

我想知道如何克隆 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 文本。

Table View

是的,我正在使用 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/

相关文章:

ios - 使用 uitableviewcontroller 时,无论行数如何,如何将按钮添加到屏幕底部?

iOS 8 当键盘出现时将 UIView 向上移动 |问题

objective-c - 多 View 应用程序的问题

jQuery 制作 HTML 的副本并存储它以供以后检索

ruby - 哪些 Ruby 类支持 .clone?

iphone - 在 Objective-C 中解析 JSON 响应

ios - 截图并以编程方式发送

ios - 如何使整个区域可点击?

ios - 对 UIView 的起源感到困惑

java - 复制任何类型的对象