嗨,我在将图像添加到按钮时遇到问题。图像存储在 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;
text.placeholder=@"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];
}
}