我刚刚在我的应用程序中实现了一个书签/收藏夹功能,来自 a 的收藏夹tableview,使用以下代码,使用NSUserDefaults. 该单元格有 2 个标签,项目名称和价格 - 存储在数组中 -theArray和thePriceArray-> 如下所示:

NSIndexPath *indexPath = [_ListTableView indexPathForCell:(UITableViewCell *) [[sender superview] superview]];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSMutableArray *OrderList = [[defaults objectForKey:ORDER_KEY] mutableCopy];
if (!OrderList) OrderList = [NSMutableArray array];
[OrderList addObject:[theArray objectAtIndex:indexPath.row]];
[OrderList addObject:[thePriceArray objectAtIndex:indexPath.row]];
[defaults setObject:OrderList forKey:ORDER_KEY];
[defaults synchronize];
我现在将两个数组 theArray&添加thePriceArray到NSMutableArray. 我现在想在另一个中显示这些信息(来自数组的信息)tableview。我这样做是这样的:
在我的viewDidAppear:
NSUserDefaults *defaults = kSettings;
NSMutableArray *theOrderList = [NSMutableArray arrayWithArray:[defaults objectForKey:ORDER_KEY]];
并显示以下内容tableview:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [theOrderList count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"TheTableCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
cell.textLabel.text = [theOrderList objectAtIndex:indexPath.row];
return cell;
}
这几乎可以按我的意愿工作,显示 和 的内容theArray,thePriceArray但是在一个长长的列表中,如下所示:

我希望“键和值”在一个单元格中,所以价格和项目名称在一个单元格中(Hat - 30)而不是单独的,我该怎么做?我曾尝试使用 a NSDictionary,但没有运气,我可以使用NSDictionary它吗?