Iphone objective-c中具有性质的记忆问题

Iphone objective-c中具有性质的记忆问题,iphone,objective-c,Iphone,Objective C,UIImage*image=[[UIImage alloc]initWithData:data]; ((YKSubCategory*)[\u subCategories objectAtIndex:connection.tag-1])。menuImage=image; [图片发布] 这是我写的代码。数据已存在,并且已创建设计的图像。(我已经用imageview测试过了,图像出现了)。 当我尝试设置menuImage属性时,问题出现了。它不会被设置。我不知道为什么。因此menuImage属性的值保

UIImage*image=[[UIImage alloc]initWithData:data]; ((YKSubCategory*)[\u subCategories objectAtIndex:connection.tag-1])。menuImage=image; [图片发布]

这是我写的代码。数据已存在,并且已创建设计的图像。(我已经用imageview测试过了,图像出现了)。 当我尝试设置menuImage属性时,问题出现了。它不会被设置。我不知道为什么。因此menuImage属性的值保持为零。 以下是属性定义:

@property (nonatomic, retain) UIImage *menuImage;
有什么问题吗


编辑:

我已经为walkytalky的请求划分了代码。 以下是我编写的代码:

UIImage *image = [[UIImage alloc] initWithData:data];
YKSubCategory *subCategory = (YKSubCategory *)[_subCategories objectAtIndex:connection.tag - 1];
subCategory.menuImage = image;
[image release];
[_tableView reloadData];
有趣的是,子类别变量就是我所期望的变量。然后在设置menuImage属性之后,设置该属性的变量。我可以在调试器中看到,但在数组中没有设置。这是什么?

(i)你有
@synthesis
-d
菜单图像吗

(ii)您能否将setter行分解,首先获取
yk子类别
对象,并测试它是否存在,以及它是否符合您的预期

YKSubCategory* target = (YKSubCategory*)[_subCategories objectAtIndex:connection.tag - 1];
NSLog("subcategory target = %@", target);
// other tests here
target.menuImage = image;
否则,我认为我们没有足够的信息来解决这个问题。设置后,菜单图像立即是什么样子


编辑:当你说“数组中的对象未设置”时,你的意思是数组中的实际对象与你刚才在那里设置的对象不同吗?或者当您在加载表数据时返回数组时,
menuImage
不再设置?或者它只是不显示在表中

第一个从表面上看似乎不可能,所以让我们考虑第二个和第三个

如果在您返回菜单图像时,菜单图像已被重置,则肯定有一些代码在某处对其进行了设置。这可能不会经过属性访问器,但对于初学者,您可以显式实现setter来记录更改:

- (void) setMenuImage:(UIImage*)newImage
{
    if ( newImage != menuImage )
    {
        NSLog(@"Changing menuImage from %@ to %@", menuImage, newImage);
        [newImage retain];
        [menuImage release];
        menuImage = newImage;
    }
}
另一种可能是数组中实际的
YKSubCategory
对象已更改,甚至数组不同,因此请检查两个位置的指针是否相同


另一方面,如果设置了菜单图像ivar,但它没有显示在表中,则需要检查绘图代码。

是的,我已合成。等一下我要分手了。