iOS removing view

I have two views, viewA and viewB. I load viewB on top of viewA with

[self.view addSubview: viewB.view];

I wan't to remove viewB, but I don't how to do it. I tried

[self.view removeFromSuperview];

but this isn't working. How can I do this?

Answers


Call -removeFromSuperview on viewB.view.


To remove viewB's view from its superview, you need to call removeFromSuperview on that view.

[viewB.view removeFromSuperview];

From the UIView class reference.

removeFromSuperview

Unlinks the receiver from its superview and its window, and removes it from the responder chain.


You are on the right track by using the removeFromSuperView. But you need to send the message to the view that you want to remove. Just as Till example

[viewB.view removeFromSuperview];

However, you might not have a handle to viewB by the time you want to remove it if you are not using property and synthesize method. I would make use of @property and @synthesize. So you can use:

[self.viewB.view removeFromSuperview];

Another way is using this: (assuming that your viewB.view is the last view you added to viewA.view

[[self.view.subviews objectAtIndex:(self.view.subviews.count - 1)]removeFromSuperview];

You can get a list of all subviews of your viewA by:

NSLog(@"subviews of viewA.view: %@",self.view.subviews);

Need Your Help

hashing password using md5 and a control field

java android md5

I want to hash a password using MD5 and I have given a string named MD5ControlHash

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.