2013-05-31 37 views
0

我正在開發一款iPad應用程序,併爲我的程序使用了UISplitview。 現在我的程序的主要詳細視圖中,我有一個uiscrollview我添加了兩個標籤。無法移除uiscrollview

UIScrollView *scroll=[[UIScrollView alloc]initWithFrame:CGRectMake(0,0, self.view.frame.size.width,self.view.frame.size.height)]; 
    scroll.contentSize=CGSizeMake(320, 1600); 
    scroll.showsHorizontalScrollIndicator=YES; 
    scroll.backgroundColor=[UIColor clearColor]; 

    [self.view addSubview:scroll]; 

這是我在第一個主頁上創建的代碼。現在想象一下,我們推動了第二種觀點,從第二個觀點我可以訪問一切說

[self.detailViewController.view addSubview:detailViewController.Image]; 

但是當我嘗試添加標籤的子視圖說

[self.detailViewController.view.scoll... 

,但我不能找到滾動對象,但第一個視圖中的滾動背景會在第二個視圖中出現。我不能改變第一個視圖的背景。

我決定做第一個滾動視圖的第一個(它的工作原理),但我更想知道如何訪問我在整個程序中創建的第一個視圖,因爲它會否定我不得不浪費空間創建滾動視圖。但如果我要創建我需要我希望能夠以某種方式刪除或釋放他們,所以從一個滾動視圖的圖片沒有傳送一路到的意見太多滾動型3

謝謝

+0

scroll是您顯示的代碼中的局部變量。如果您需要從該方法之外訪問它,則應該將其設置爲detailViewController的屬性。 – rdelmar

回答

0

你必須爲您想要從其他類訪問的所有變量創建屬性。所以你的情況

DetailsViewController.h

@interface DetailsViewController : UIViewController { 

    // class member variables here that can be accessed 
    // anywhere in your class (only in your class) 
} 

@property(nonatomic, strong) 
    //retain instead of strong if you are not using ARC or other types (weak, copy, readonly) 
    SomeClassThatYouHave *propertyThatCanBeAccessed 
//declare here public instance methods 
@end 

在你DetailsViewController.m你將有:

@interface DetailsViewController (Private) 
//declare private methods here or private properties 
@end 

@implementation DetailsViewController 
@synthesize propertyThatCanBeAccessed; 

//methods implementation here 
@end 

現在,您可以訪問您DetailsViewController的財產一樣detailsViewControllerInstance.propertyThatCanBeAccessed但你必須分配/初始化實例。

希望這會給你一個關於未來班級結構的想法。

+0

完美!我可以看到它,謝謝 –