UIView

Discussion in 'iOS Programming' started by Nnavick, Apr 24, 2011.

  1. Nnavick
    Expand Collapse
    macrumors regular

    Joined:
    Oct 13, 2010
    #1
    Hi ,
    I have in my .xib file two views,
    one is the main view that connected to the view outlet from the file's owner and
    the second one I named ABC from the code

    -IBOutlet UIView *ABC;

    my question is how do I call the ABC view from another class if ABC view isn't
    connected to the "view" outlet from the file's owner

    I can call the main view from another class

    Code:
    	LoginRegisterViewController *viewController = [[LoginRegisterViewController alloc] initWithNibName:@"LoginRegisterViewController" bundle:nil];
    	self.loginRegisterViewController = viewController;
    	[viewController release];
    
     UIView *newView = loginRegisterViewController.view;
        [self.view addSubview:newView];
        [newView release];
    
    but I don't know how to call the ABC view.
    maybe I can use the ABC view as a @property and call it from the other class?

    Thanks for the help!!!
     
  2. robbieduncan
    Expand Collapse
    Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    Same way you would any other member variable of a class. Either make it a property and synthesise the accessors or write your own accessors.
     
  3. Nnavick
    Expand Collapse
    thread starter macrumors regular

    Joined:
    Oct 13, 2010
    #3
    UIView *newView = loginRegisterViewController.abc;

    It's shows me blank view
    what is the problem?
     
  4. robbieduncan
    Expand Collapse
    Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #4
    How should I know? You've not posted the code. I'm not psychic.
     
  5. Nnavick
    Expand Collapse
    thread starter macrumors regular

    Joined:
    Oct 13, 2010
    #5
    abc class
    .h
    Code:
    -IBOutlet UIView *abc
    Code:
    @property(nonatomic,retain)   IBOutlet UIView *abc;
    .m
    Code:
    @synthesize abc;


    other class
    Code:
    LoginRegisterViewController *viewController = [[LoginRegisterViewController alloc] initWithNibName:@"LoginRegisterViewController" bundle:nil];
    	self.loginRegisterViewController = viewController;
    	[viewController release];
    
     UIView *newView = loginRegisterViewController.abc;
        [self.view addSubview:newView];
        [newView release];
     
  6. robbieduncan
    Expand Collapse
    Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #6
    And that's still correctly connected in Interface Builder? If you check the value of abc in awakeFromNib inside LoginRegisterViewController is it nil?
     
  7. dejo
    Expand Collapse
    Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #7
    You sure you want to release newView? Are you following the memory management rules?
     
  8. Nnavick
    Expand Collapse
    thread starter macrumors regular

    Joined:
    Oct 13, 2010
    #8
    yep,it's nil,I haven't call it before.

    Dejo,I don't see any problem releasing newView(?)
     
  9. robbieduncan
    Expand Collapse
    Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #9
    That would seem to be a problem...

    This is also a problem.
     
  10. dejo
    Expand Collapse
    Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #10
    Memory Management Programming Guide

    The Fundamental Rule:
    • You only release or autorelease objects you own.

    Do you own newView?
     
  11. Sykte, Apr 25, 2011
    Last edited by a moderator: Apr 25, 2011

    Sykte
    Expand Collapse
    macrumors regular

    Joined:
    Aug 26, 2010
    #11
    You will save time by reading the documentation. The code above could easily be 2 lines instead of 6. Don't rush learning the basics.
     

Share This Page