【发布时间】:2012-11-08 16:47:07
【问题描述】:
今天我遇到了无法复制的错误,这让我很困惑。 好的小背景:
我目前正在开发将标签栏控制器作为初始视图控制器的应用程序。有几个导航控制器连接到不同的标签栏项目。
其中一个是 tableViewController,由 JSON 填充。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"SimpleTableItem";
SimpleTableCell *cell = (SimpleTableCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"SimpleTableCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
//NSMutableArray for storing loaded values
[pics addObject:imageLoad];
[names addObject:[aucdict objectForKey:@"name"]];
[idcka addObject:[aucdict objectForKey:@"auction_id"]];
// Configure the cell...
cell.nameLabel.text = [aucdict objectForKey:@"name"];
cell.priceLabel.text = [NSString stringWithFormat:@"%@",priceString];
cell.timeLabel.text = [NSString stringWithFormat:@"%@",timeString];
cell.thumbnailImageView.image = imageLoad;
return cell;}
点击行后,我执行 performSegueWithIdentifier:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[self performSegueWithIdentifier:@"showAuctionDetail" sender:self];}
在 prepareForSegue 中,我将一些数据发送到下一个 ViewController
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
namesArray = [[NSArray alloc] initWithArray:names];
picsArray =[[NSArray alloc] initWithArray:pics];
IDarray = [[NSArray alloc] initWithArray:idcka];
if ([segue.identifier isEqualToString:@"showAuctionDetail"])
{
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
detailViewController *dViewController = segue.destinationViewController;
dViewController.selectedAuctionTitle = [namesArray objectAtIndex:indexPath.row];
dViewController.auctionPic = [picsArray objectAtIndex:indexPath.row];
dViewController.id_aukcie = [IDarray objectAtIndex:indexPath.row];
}}
现在我的问题来了。有时(这真的让我很困惑,因为我还没有发现它是什么时候发生的)当我启动应用程序并点击某行时,我得到完全不同的数据传递给 DetailViewController。我能猜到的唯一一件事是我的数组与实际的 JSON 响应不同(它们包含更多或更少的值)。但这意味着,如果我点击表格中的第一个或最后一个项目(索引超出范围或类似的东西),我的应用程序会崩溃,这从未发生过。
我已经看到这个错误可能随机发生了 5 次。我尝试连续运行和退出应用程序 20 次,但只发生了一次。
附:我知道类名(detailViewController)应该以大写字母开头,对此我深表歉意:)
已编辑:按照 rdelmar 的建议
【问题讨论】:
标签: ios json uitableview nsarray uistoryboardsegue