2013-05-31 34 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

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