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

您的数组超出索引。也许您没有实例化它,或者您尝试访问此数组的空索引。. .

于 2012-09-28T12:26:57.190 回答