0

我有一个从网站下载 JSON 文件并将其显示在表格视图中的代码。我的下一步是在详细列表中显示标题(人名)。

我怎样才能做到这一点?我无法进入主屏幕上显示的数据。

这是在第一个屏幕上显示名称的代码。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath
(NSIndexPath *)indexPath
{
NSString *cellIdentifier = @"BasicCell";
    UITableViewCell *myCell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    // Get the location to be shown
    Location *item = _feedItems[indexPath.row];

// Get references to labels of cell
myCell.textLabel.text = item.Name;

    return myCell;
}

--- 开始编辑-----

我在 HomeModel.M 类中有一个 NSDictionary。

  for (int i = 0; i < jsonArray.count; i++)
{
    NSDictionary *jsonElement = jsonArray[i];

    // Create a new location object and set its props to JsonElement properties
    Location *newLocation = [[Location alloc] init];
    newLocation.Name = jsonElement[@"Email"];
    newLocation.list = jsonElement[@"lijst"];
    newLocation.Password = jsonElement[@"Password"];

    // Add this question to the locations array
    [_locations addObject:newLocation];
}

// Ready to notify delegate that data is ready and pass back items
if (self.delegate)
{
    [self.delegate itemsDownloaded:_locations];
}

--- 结束编辑----

所以基本上我想要的是在 ToGetList 类中显示相同的名称......

像这样的东西:

- (void)viewDidLoad
    {
        [super viewDidLoad];
        self.nameLabel.text = item.Name //Reference to the ViewController.m class;
        // Do any additional setup after loading the view.
    }
4

1 回答 1

0

创建一个包含名称、职业等单元格组件的模型。将 JSON 中的所有数据存储在数组中。在

   - (UITableViewCell *)tableView:(UITableView *)tableView
     cellForRowAtIndexPath:(NSIndexPath *)indexPath 

方法

self.timeSheetModel = [self.timeSheetListArray objectAtIndex:indexPath.row];

  - (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

self.detailVC = [[DetailVC alloc]init];

//Create a property model in your detailVC assign it.

self.detailVC.model = [self.timeSheetListArray objectAtIndex:indexPath.row];

//Pass the model . You will get the data in your detailVC of the selected cell.

[self.navigationController pushViewController:self.detailVC animated:YES];

}

在您的 detailVC 中,您可以直接访问这些值

self.myNameLabel.text  = self.model.name;
于 2014-04-21T04:01:36.570 回答