如果类别包含项目,则展开/折叠UiTableViewCell

时间:2014-02-25 12:44:19

标签: ios objective-c uitableview

当我的手机充满时,我需要帮助扩展/折叠我的手机。我之前的post解释了我想要实现的目标并回答了我的问题,但我不知道如何在此设置中扩展单元格。我查看了代码示例,但它们对我的需求来说太复杂了。如果有人能把我送上正确的方向。

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


[tableView deselectRowAtIndexPath:indexPath animated:YES];

NSString *key = [[self.tableObjects allKeys] objectAtIndex:indexPath.section];
NSArray *sectionobjects = (NSArray*)[self.tableObjects objectForKey:key];

id object = [sectionobjects objectAtIndex:indexPath.row];

//They selected a product
if ([object isKindOfClass:[ProductObject class]]) {

    ProductObject *product = (ProductObject*)object;

    NSLog(@"%@", product.productTitle);
    NSLog(@"%@", product.productCode);
    NSLog(@"%@", product.productId);
}


//They selected a Category
else if ([object isKindOfClass:[CategoryObject class]]) {

    //Check to see if the CategoryObject has any ProductObjects associated with it
    if ([(CategoryObject*)object products]) {

        //Now you will need to pass array of ProductObjects this along to your next view controller.
        NSArray *cateogryProducts = [(CategoryObject*)object products];

        //For demonstration purposes, i'll run through and print out all the Products for this Category
        [cateogryProducts enumerateObjectsUsingBlock:^(ProductObject *product, NSUInteger idx, BOOL *stop) {
            NSLog(@"%@", product.productTitle);
            NSLog(@"%@", product.productCode);
            NSLog(@"%@", product.productId);
        }];
    }

}

@random感谢你的输入到目前为止。

我上一篇文章要查看我的所有代码:Multi level categories with items on all levels in UITableView

我想要实现:单击后显示(展开/折叠)位于第一级单元格(类别)中的项目(产品)。然后,可以单击新单元格(产品)并打开一个新的视图控制器

添加了我想尝试做的图片。enter image description here

0 个答案:

没有答案