【问题标题】:How to send data from MasterView to DetailView如何将数据从 MasterView 发送到 DetailView
【发布时间】:2013-10-27 05:26:40
【问题描述】:

在我的应用程序中,我在 UIListView 上显示对象列表。 (MasterViewController.m)

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
    ObrasData *obra = [self.arrObras objectAtIndex:indexPath.row];
    cell.textLabel.text = obra.descripcion;
    return cell;
}

我试图显示来自对象的所有数据,在这种情况下,我只加载一个字段来测试应用程序。 (DetailViewController.m)

- (void)configureView
{
    // Update the user interface for the detail item.

    if (self.detailItem) {
        self.NombreObra.text = [self.detailItem description];
    }
}

当我进入 DetailView 时,我在标签中看到以下文本 ->

<ObrasData: 0x892b4b0>

那么,从对象加载所有数据的最佳方式是什么?这是我加载数组的地方:

   ObrasData *obra1 = [[ObrasData alloc] initWithID:[NSNumber numberWithInt:1] presupuesto:@"100" description:@"obra de prueba" aasm_state:@"En proceso" clienteID:@"dm2"];

    NSMutableArray *arrObras = [NSMutableArray arrayWithObjects:obra1, nil];
    UINavigationController *navController = (UINavigationController *) self.window.rootViewController;
    MasterViewController *masterController = [navController.viewControllers objectAtIndex:0];
    masterController.arrObras = arrObras;

感谢您的帮助。

【问题讨论】:

  • “从对象中加载所有数据”是什么意思?在哪里加载?您想将detailItem 中的数字和字符串添加到屏幕上吗?创建一些 UI 并访问 ObrasData 的属性。
  • 我已经创建了一个 UITextView,问题是文本显示:ObrasData: 0x892b4b0

标签: objective-c detailview


【解决方案1】:

“description”是 NSObject 上的一个方法,它返回一个对象的文本描述,你看到的是默认实现(它只是打印地址)。

这意味着您没有实现覆盖“描述”以返回其他内容的方法。

没有看到 ObrasData 的实现是什么样子,很难为您提供更多指导。

编辑,看到实现后,我看到您有一个名为“描述”(西班牙语)的属性,您在 init 方法中对其进行了初始化。我假设您实际上想要这样做:

[self.detailItem descripcion]

另一方面,如果您确实想描述整个对象,那么您需要覆盖描述方法,例如

- (NSString *)description
{
  return [NSString <create your description yourself here>];
}

【讨论】:

  • 在这个问题中我展示了实现:link,谢谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-04-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-01-15
  • 2017-01-11
  • 2013-03-30
相关资源
最近更新 更多