Sleep Paralysis
Sleep Paralysis

Reputation: 469

Cannot remove a uiscrollview

I am working on an iPad app and i utilise a UISplitview for my program. Now on the main detail view of my program i have a uiscrollview on which i add two labels.

  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];

This is the code i create on the first main page. Now imagine we push the second view, from that second view i can access everything by saying

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

but when i try to add labels to the subview saying

[self.detailViewController.view.scoll...

but i cannot find the scroll object, BUT the background of the scroll set in the first view comes over in the second view. AND i cannot change the background of the first view.

I decided to make a second scrollview untop of the first (which works) but i much rather know how i can access the first view i created throughout the whole program since it would negate me having to waste space creating scroll views. but if i have to create all the views i need i want to be able to somehow delete or release them so the picture from scrollview one doesn't get transferred all the way too scrollview 3

Thank You

Upvotes: 0

Views: 69

Answers (1)

danypata
danypata

Reputation: 10175

You have to create properties for all the variables that you want to access from other classes . So in your case

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

In your DetailsViewController.m you will have:

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

@implementation DetailsViewController
@synthesize propertyThatCanBeAccessed;

//methods implementation here
@end

Now you can access the property of your DetailsViewController like detailsViewControllerInstance.propertyThatCanBeAccessed but you must alloc/init the instance.

Hope that this will give you an idea of class structure in the future.

Upvotes: 0

Related Questions