嗨我有一個向按鈕添加圖像的問題。圖像存儲在一個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