0

これは、UITableView に星評価を実装しようとしたときに発生したエラーです。2012-09-28 18:41:33.698 PlanMyDay[4533:c07] adssadgadf (

( "4.5", "4.1", 4, "3.9", "4.2", "4.1", "", "4.3", "3.9", "4.4", "", 4, "3.9", "3.9" 、""、4、"3.2"、"3.6"、"3.3"、"3.8" )

"2012-09-28 17:33:38.741 PlanMyDay[4211:c07] * キャッチされていない例外 'NSRangeException' が原因でアプリを終了しています。理由: '* -[__NSArrayM objectAtIndex:]: 境界を超えたインデックス 1 [0 .. 0]'

* First throw call stack: (0x1873022 0x13e5cd6 0x185fd88 0x4da43 0x5e2c54 0x5e33ce 0x5cecbd 0x5dd6f1 0x586d42 0x1874e42 0x1ba9679 0x1bb3579 0x1b384f7 0x1b3a3f6 0x1b39ad0 0x184799e 0x17de640 0x17aa4c6 0x17a9d84 0x17a9c9b 0x1a897d8 0x1a8988a 0x548626 0x2b82 0x2af5) terminate called throwing an exception(lldb) "

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

        static NSString *CellIdentifier = @"Cell";

        // if a cell can be reused, it returns a UITableViewCell with the associated identifier or nil if no such cell exists
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

        // if no cell to reuse, then create a new one
        if (cell == nil)
        {


    NSDictionary *testrate =[ratings1 objectAtIndex:indexPath.row];
    NSString *str=[[NSString alloc]initWithFormat:@"%@",testrate];
    NSInteger n=[str intValue];
    NSLog(@"workrate:%@", str);

   if (n >=4)
        {


    CGRect starFrame = CGRectMake(65,60, 15, 15);
    //CGSize  starFrame = CGSizeMake(20,20);
    UIImageView *starImage = [[[UIImageView alloc] initWithFrame:starFrame] autorelease];
    starImage.image = [UIImage imageNamed:@"star.png"];
    starImage.backgroundColor=[UIColor clearColor];
    [cell.contentView addSubview:starImage];

    CGRect starFrame1 = CGRectMake(80,60, 15, 15);
    UIImageView *starImage1 = [[[UIImageView alloc] initWithFrame:starFrame1 ] autorelease];
    starImage1.image = [UIImage imageNamed:@"star.png"];
    starImage1.backgroundColor=[UIColor clearColor];
    [cell.contentView addSubview:starImage1];

    CGRect starFrame2 = CGRectMake(95,60, 15, 15);
    UIImageView *starImage2 = [[[UIImageView alloc] initWithFrame:starFrame2 ] autorelease];
    starImage2.image = [UIImage imageNamed:@"star.png"];
    starImage2.backgroundColor=[UIColor clearColor];
    [cell.contentView addSubview:starImage2];

    CGRect starFrame3 = CGRectMake(110,60, 15, 15);
    UIImageView *starImage3 = [[[UIImageView alloc] initWithFrame:starFrame3 ] autorelease];
    starImage3.image = [UIImage imageNamed:@"star.png"];
    starImage3.backgroundColor=[UIColor clearColor];
    [cell.contentView addSubview:starImage3];

    CGRect starFrame4= CGRectMake(125,60, 15, 15);
    UIImageView *starImage4 = [[[UIImageView alloc] initWithFrame:starFrame4 ] autorelease];
    starImage4.image = [UIImage imageNamed:@"star.png"];
    starImage4.backgroundColor=[UIColor clearColor];
    [cell.contentView addSubview:starImage4];

    }
    else if(n >=3&&n<=4)
    {
        CGRect starFrame = CGRectMake(65,60, 15, 15);
        //CGSize  starFrame = CGSizeMake(20,20);
        UIImageView *starImage = [[[UIImageView alloc] initWithFrame:starFrame] autorelease];
        starImage.image = [UIImage imageNamed:@"star.png"];
        starImage.backgroundColor=[UIColor clearColor];
        [cell.contentView addSubview:starImage];

        CGRect starFrame1 = CGRectMake(80,60, 15, 15);
        UIImageView *starImage1 = [[[UIImageView alloc] initWithFrame:starFrame1 ] autorelease];
        starImage1.image = [UIImage imageNamed:@"star.png"];
        starImage1.backgroundColor=[UIColor clearColor];
        [cell.contentView addSubview:starImage1];

        CGRect starFrame2 = CGRectMake(95,60, 15, 15);
        UIImageView *starImage2 = [[[UIImageView alloc] initWithFrame:starFrame2 ] autorelease];
        starImage2.image = [UIImage imageNamed:@"star.png"];
        starImage2.backgroundColor=[UIColor clearColor];
        [cell.contentView addSubview:starImage2];



    }


    return cell;
}

私のプロジェクトを完了するのを手伝ってください

4

2 に答える 2

0

メソッド viewWillAppear で ratigs1 を正しく初期化する

于 2012-09-28T12:45:17.243 に答える
0

配列のインデックスが不足しています。インスタンス化していないか、この配列の null インデックスにアクセスしようとしている可能性があります。. .

于 2012-09-28T12:26:57.190 に答える