PDA

View Full Version : UIView




Nnavick
Apr 24, 2011, 06:28 AM
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

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!!!



robbieduncan
Apr 24, 2011, 06:30 AM
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.

Nnavick
Apr 24, 2011, 06:50 AM
UIView *newView = loginRegisterViewController.abc;

It's shows me blank view
what is the problem?

robbieduncan
Apr 24, 2011, 06:51 AM
UIView *newView = loginRegisterViewController.abc;

It's shows me blank view
what is the problem?

How should I know? You've not posted the code. I'm not psychic.

Nnavick
Apr 24, 2011, 07:51 AM
abc class
.h
-IBOutlet UIView *abc
@property(nonatomic,retain) IBOutlet UIView *abc;
.m
@synthesize abc;



other class
LoginRegisterViewController *viewController = [[LoginRegisterViewController alloc] initWithNibName:@"LoginRegisterViewController" bundle:nil];
self.loginRegisterViewController = viewController;
[viewController release];

UIView *newView = loginRegisterViewController.abc;
[self.view addSubview:newView];
[newView release];

robbieduncan
Apr 24, 2011, 08:00 AM
And that's still correctly connected in Interface Builder? If you check the value of abc in awakeFromNib inside LoginRegisterViewController is it nil?

dejo
Apr 24, 2011, 08:15 AM
You sure you want to release newView? Are you following the memory management rules?

Nnavick
Apr 24, 2011, 08:39 AM
And that's still correctly connected in Interface Builder? If you check the value of abc in awakeFromNib inside LoginRegisterViewController is it nil?

yep,it's nil,I haven't call it before.

Dejo,I don't see any problem releasing newView(?)

robbieduncan
Apr 24, 2011, 08:41 AM
yep,it's nil,I haven't call it before.
That would seem to be a problem...

Dejo,I don't see any problem releasing newView(?)
This is also a problem.

dejo
Apr 24, 2011, 07:36 PM
Dejo,I don't see any problem releasing newView(?)

Memory Management Programming Guide (http://developer.apple.com/library/ios/#documentation/cocoa/Conceptual/MemoryMgmt/MemoryMgmt.html)

The Fundamental Rule:

You only release or autorelease objects you own.


Do you own newView?

Sykte
Apr 25, 2011, 07:20 AM
LoginRegisterViewController *viewController = [[LoginRegisterViewController alloc] initWithNibName:@"LoginRegisterViewController" bundle:nil];
self.loginRegisterViewController = viewController;
[viewController release];

UIView *newView = loginRegisterViewController.view;
[self.view addSubview:newView];
[newView release];


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.