【发布时间】:2014-03-14 01:33:59
【问题描述】:
我有一个组合数组,就是组合API1和API2的新闻标题结果。如何从新组合数组中的每个对象中获取“标题文本”?
现在,当我一次只使用一个 API 时,我的应用程序运行良好。但是现在我将对象放在一个组合数组中,我无法弄清楚如何显示cell.headline.text,因为我从中提取的源不再来自同一个确切的 JSON(即可能是从API1 或可能从 API2 中提取)。
我正在使用 RestKit。
WebListViewController.m(仅使用 API1)
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
WebListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"WebListCell"];
F *fLocal = [hArray objectAtIndex:indexPath.row];
NSString *headlineText = [NSString stringWithFormat:@"%@", fLocal.headline];
cell.headlineLabel.text = headlineText;
}
WebListViewController.m(仅使用 API2)
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
WebListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"WebListCell"];
D *dLocal = [iArray objectAtIndex:indexPath.row];
NSString *otherHeadlineText =
[NSString stringWithFormat:@"%@", dLocal.head.headline];
cell.headlineLabel.text = otherHeadlineText;
}
WebListViewController.m(尝试结合 API1 + API2)
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return array.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// This is where I need help. Don't know if this line below even makes sense?
WebListViewController *combinedArray = [array objectAtIndex:indexPath.row];
}
【问题讨论】:
标签: ios arrays uitableview restkit