numberOfRowsInSection未返回正确的行数

时间:2014-09-29 17:32:58

标签: objective-c arrays uitableview

对于我的UITableView中的部分数量,我使用以下函数:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return _matchCenterArray.count;
}

这样可以正常工作,并在表格中显示正确的部分数量。它引用的_matchCenterArray如下所示:

(
        {
        "Top 3" =         (
                        {
                "Image URL" = "http://thumbs4.ebaystatic.com/m/mu05CM1bactFTAWZjesohNg/140.jpg";
                "Item URL" = "http://www.ebay.com/itm/Nexus-7-Latest-Model-16GB-Wi-Fi-7in-Black-2nd-Generation-2013-/281443895415?pt=US_Tablets";
                Price = "170.0";
                Title = "Nexus 7 (Latest Model) 16GB, Wi-Fi, 7in - Black (2nd) Generation 2013";
            },
                        {
                "Image URL" = "http://thumbs4.ebaystatic.com/m/mjkaCfDBdTQ6S-VTD0kFimA/140.jpg";
                "Item URL" = "http://www.ebay.com/itm/Asus-Google-Nexus-7-2nd-Generation-Tablet-7-16GB-Android-4-3-/351173222631?pt=US_Tablets";
                Price = "165.59";
                Title = "Asus Google Nexus 7 2nd Generation Tablet 7\" 16GB Android 4.3 ";
            },
                        {
                "Image URL" = "http://thumbs4.ebaystatic.com/m/mjIENDWxrHTfcrO_Tmu4-zw/140.jpg";
                "Item URL" = "http://www.ebay.com/itm/Google-Nexus-7-16GB-HD-K008-NEXUS7-ASUS-2B16-2nd-Gen-Tablet-Priority-Ship-/301315740555?pt=US_Tablets";
                Price = "164.99";
                Title = "Google Nexus 7 16GB HD K008 NEXUS7 ASUS-2B16 2nd Gen Tablet Priority Ship";
            },
                        {
                "Search Term" = "nexus 7 16gb";
            }
        );
    },
        {
        "Top 3" =         (
                        {
                "Image URL" = "http://thumbs3.ebaystatic.com/m/mbSjXw608gtlLhYC5GbrbOg/140.jpg";
                "Item URL" = "http://www.ebay.com/itm/rolex-datejust-/301318985642?pt=Wristwatches";
                Price = "400.0";
                Title = "rolex datejust";
            },
                        {
                "Image URL" = "http://thumbs3.ebaystatic.com/m/mx2eBCLXBEY30DXIIMrm_MQ/140.jpg";
                "Item URL" = "http://www.ebay.com/itm/VINTAGE-LADIES-ROLEX-STANDARD-17J-GOLD-FILLED-WATCH-WORKING-NICE-/111466728842?pt=Wristwatches";
                Price = "349.99";
                Title = "VINTAGE LADIES ROLEX STANDARD 17J GOLD FILLED WATCH WORKING NICE  ";
            },
                        {
                "Image URL" = "http://thumbs2.ebaystatic.com/m/mj7-GblU-4Al2X5q0sRvkfw/140.jpg";
                "Item URL" = "http://www.ebay.com/itm/Rolex-17000-Quartz-Datejust-BLACK-DIAL-5035-/271610085029?pt=Wristwatches";
                Price = "400.0";
                Title = "Rolex 17000 Quartz Datejust  BLACK DIAL 5035";
            },
                        {
                "Search Term" = rolex;
            }
        );
    }
)

据我所知,它是一个前3个数组的数组。在这种情况下,有两个 Top 3 数组,它们分为两部分。就每个部分的行数而言,我希望它是前3个数组中的字典对象的数量。

在这种情况下,如果我没有弄错的话,他们似乎都在该数组中有4个词典。我尝试使用下面的函数执行此操作,但每个部分只显示一行:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    NSArray *currentSectionArray = _matchCenterArray[section];
    return currentSectionArray.count;

    return 3;
}

2 个答案:

答案 0 :(得分:1)

你的数据源对我的看法是有字典数组,所以与一个部分相关联的每个对象都是一个字典,而不是一个数组,并且为了获得这个字典的数组你需要访问密钥的对象,在这种情况下" Top 3"获取该部分的数组:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    NSDictionary *currentSectionDictionary = _matchCenterArray[section];
    NSArray *top3ArrayForSection = currentSectionDictionary[@"Top 3"];
    return top3ArrayForSection.count;
}

答案 1 :(得分:0)

_matchCenterArray [section]应该是字典,对吗?您是否可以将NSDictionary分配给NSArray变量? 也许试试

NSArray *currectSectionArray = [_matchCenterArray[section] allKeys];
return [currentSectionArray count];