0

我正在开发一个 iPad 应用程序,并为我的程序使用 UISplitview。现在在我的程序的主要细节视图上,我有一个 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

谢谢你

4

1 回答 1

0

您必须为要从其他类访问的所有变量创建属性。所以在你的情况下

详细信息ViewController.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但您必须分配/初始化实例。

希望这能让您对未来的班级结构有所了解。

于 2013-05-31T18:42:45.990 回答