我想在UITableViewCell里面显示子单元格。我有两个包含groupname和groupid的数组。我能够通过使用下面的代码在具有自定义TableViewCell的tableview中显示组名。在UITableViewCell里面显示子单元
NSArray *groupIdArr;
NSArray *groupNameArr;
groupNameArr (
ANTISERA,
CLIA,
COAGULATION,
CONFIRMATORY,
ELISA,
IMMUNOLOGY,
MISC,
RAPID
)
groupIdArr (
20,
21,
22,
23,
19,
31,
29,
18
)
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [groupIdArr count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"ProductGroupTableViewCell";
ProductGroupTableViewCell *cell = (ProductGroupTableViewCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"ProductGroupTableViewCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
cell.productGroupNameLbl.text = [groupNameArr objectAtIndex:indexPath.row];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *saveGroupId = [groupIdArr objectAtIndex:indexPath.row];
[[NSUserDefaults standardUserDefaults] setObject:saveGroupId forKey:@"SavedGroupId"];
[[NSUserDefaults standardUserDefaults] synchronize];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *productListVC = [storyboard instantiateViewControllerWithIdentifier:@"ProductsListViewController"];
[self.navigationController pushViewController:productListVC animated:YES];
}
当用户点击TableViewCell用户可以看到与所选的groupid像下面,他可以选择的产品的产品列表。
选择产品的用户后,将完成按按钮返回到上一个视图,在那里他可以看到下面的组名所选的产品。我在NSMutableArray中将选定的产品名称带到之前的视图。但我无法弄清楚如何显示下面的输出。
我试了很多找到解决方案,但没有运气。任何帮助将非常感激。
下载这个,你必须更改位代码。你有了你的愿望结果。只为你开发演示。让我知道你是否需要任何帮助。 – PSS