2013-01-02 22 views
-1

我其實寫了一個切換一些UIViews的方法。當我輸入方法時,我必須知道我目前的視圖是從超視圖中刪除這個視圖。我宣佈爲此,在頭文件的屬性:還記得我目前的看法

@property (weak, nonatomic) UIView *currentView; 

後,我改變了對我的方法有一定的看法,我想,爲了當我再次輸入法使用它分配此視圖屬性並根據要求從超級視圖中移除此視圖。該方法是這樣的:

... 
nextView = [self loadNextView]; // the view is loaded from a NIB here 
if (self) 
{ 
    [self viewWillDisappear:YES]; 
    [[self currentView] removeFromSuperview]; 
    [[self view] addSubview:nextView]; 
    [self currentView] = [self nextView]; 
... 

不幸的是,編譯器告訴我,currentView不可分配在這裏。還有另外一種希望更好的方法來爲我的目的記住治癒的觀點,還是應該採用完全不同的方式?

+0

並請學習C正確,這是一件很基本的。 – 2013-01-02 12:35:48

回答

0

取而代之的是下面這行的,

[self currentView] = [self nextView]; 

操作如下:

[self setCurrentView:[self nextView]]; 
0

你不能分配給函數或方法調用的值(它返回一個右值)。您必須使用屬性訪問語法:

self.currentView = [self nextView]; 

或顯式調用設置:

[self setCurrentView:[self nextView]]; 
0

試試這個

更換

[self currentView] = [self nextView]; 

self.currentView = [self nextView];