这是我在尝试为我的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] *终止app到期 未被捕获的异常'NSRangeException',原因:'* - [__ NSArrayM objectAtIndex:]:索引1超出边界[0 .. 0]'
* 的第一掷调用堆栈:(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)终止称为抛出异常(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;
}
请帮我完成我的项目
答案 0 :(得分:0)
您的数组已超出索引范围。也许你不是它的实例,或者你试图访问这个数组的空索引。 。
答案 1 :(得分:0)
在方法viewWillAppear
中正确初始化ratigs1