iOS使用可变阵列数据填充表

时间:2015-06-07 06:55:51

标签: ios json uitableview

我有一个JSON文件:http://astrodeer.com.au/ingredients.php已被解析。我创建了两个NSMutableArrays,一个用于成分,另一个用于列出的每个产品的评级。

首先,我用产品名称/品牌填充了我的第一张桌子:

First table view

当用户点击某个项目时,会将他们带到此页面,我尝试使用成分名称及其相应的评级填充表格。

Second Table

这是我到目前为止所拥有的。我在" numberOfRowsInSection"

收到错误

"由于未捕获的异常终止应用' NSRangeException',原因:' *** - [__ NSArrayI objectAtIndex:]:索引4超出边界[0 .. 3]&# 39;"

理想情况下,我将使用if语句根据评级号更改UIImage。但目前我正在努力研究如何显示成分名称。

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:  (NSInteger)section {

    return [_selectedProduct.ingredientsArray count];
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    NSString *cellIdentifier = @"ingredientsCell";

    UITableViewCell *myCell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    UILabel *ingLabel = (UILabel *)[myCell viewWithTag:1];
    UIImage *ingRating = (UIImage *)[myCell viewWithTag:2];

    ingLabel.text = _selectedProduct.ingredientsArray[indexPath.row];

    return myCell;
}

0 个答案:

没有答案