嗨我有一个向按钮添加图像的问题。图像存储在一个NSMutableArray属性。问题是添加并显示图像到按钮。我已验证图像已添加到阵列中。我从照相机的图像后,然后我选择要使用它应用将用下面的错误崩溃:不能将图像添加到按钮
*终止应用程序由于未捕获的异常“NSInvalidArgumentException”,原因:“ - [UIImage的长度]:无法识别的选择发送到实例0x2090b5a
代码:
displayArray=[[NSMutableArray alloc]initWithObjects:@"MedsTime_MedPic.png",@"",@"",@"", nil];
-(void)addImage1:(NSNotification*)notify
{
butImage=xapp.medicineImage;
[img setImage:xapp.medicineImage forState:UIControlStateNormal];
[displayArray replaceObjectAtIndex:0 withObject:xapp.medicineImage ];
[table reloadData];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:CellIdentifier];
}
else
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:CellIdentifier];
}
if (indexPath.section==0)
{
img=[UIButton buttonWithType:UIButtonTypeRoundedRect];
img.frame=CGRectMake(25, 15, 75, 75);
img.layer.cornerRadius=6.0;
img.clipsToBounds=YES;
img.layer.borderColor=[[UIColor grayColor]CGColor];
[cell.contentView addSubview:img];
if (xapp.isEdited==YES)
{
}
else if (xapp.isEdited==NO)
{
[img setImage:[UIImage imageNamed:[displayArray objectAtIndex:0]] forState:UIControlStateNormal];
}
[cell.contentView addSubview:img];
img.titleLabel.textColor=[UIColor blackColor];
text=[[UITextField alloc]initWithFrame:CGRectMake(105, 30, 200, 30)];
text.delegate=self;
[email protected]"Enter Medicine First";
if (xapp.isEdited==YES)
{
text.text=[[editArray objectAtIndex:0]valueForKey:@"medicineName"];
}
else{
text.text=[displayArray objectAtIndex:1];
}
[text setBorderStyle:UITextBorderStyleRoundedRect];
[cell addSubview:text];
[cell addSubview:img];
}
}
为什么要向单元格和contentView添加'img'对象?另外,你为什么要将img添加到contentView两次? – Petar 2013-03-20 12:50:48
添加什么它完全崩溃? – Pfitz 2013-03-20 12:55:49
你也可以在didSelectRowForIndexPath中发布代码吗? (我想这是发生崩溃的地方) – Petar 2013-03-20 12:57:18