0
我有一個包含UIImageView的xib中的視圖。我將圖像設置爲在xib中顯示,並正確加載和顯示。無法覆蓋從nib加載的圖像視圖與一個編程創建的
然而,在某些情況下,我想加載的圖像與在運行時另一圖像所取代,所以我這樣做:
NSArray* viewObjects = [[NSBundle mainBundle] loadNibNamed:@"ParentView"owner:self options:nil];
id object = [viewObjects objectAtIndex:0];
parentView *parentView = (ParentView*)[viewObjects objectAtIndex:0];
UIImage *image = [UIImage imageNamed: @"iconName"];
UIImageView *iv = [[UIImageView alloc] initWithImage: image];
iv.frame = parentView.icon.frame;
parentView.icon = iv;
parentView.icon是一個UIImageView。圖像變量不是零,也不是代碼執行的iv。
iconName是一個名爲「[email protected]」的.png,它在我的項目中,如果我將它設置爲.xib中的UIImageView,那麼它會正確加載並顯示。但是,如果我在.xib中設置了另一個圖標,並試圖在運行時用上面的代碼替換它,那麼它不會被替換。
我不明白爲什麼這不起作用。