I have a table in my masterView and in my detailView i have some imageView, based on different row selection in my masterView i have to remove ImageView and add some other views. Im unable to remove the ImageView.... any help ??? thanks in advance
try:
for (UIView *view in masterView.subviews){
if (view == yourImageView) {
[view removeFromSuperview];
}
}
first you provide tag values other than 0 to all your imageview
and then
for (UIView *sub in [self.view subviews]) {
use tag to find proper view and remove it from superView
}
Related
I have category for UIScrollView for customization
I need get UIScrollView.
I try
UIScrollView *scroll = nil;
for (UIView* subview in self.tableView.subviews) {
NSLog(#"%i", self.tableView.subviews.count);
if ([subview isKindOfClass:[UIScrollView class]]) {
scroll = (UIScrollView *)subview;
//some code
}
}
But it doesn't work. How I can get ScrollView? Thanks
UITableView is a subclass of UIScrollView, not a subview (or vice-versa as your code tries), so you should just use the table view directly.
UIScrollView is not subview but UIScrollView is superclass of UITableView you can call method or get variable of UIScrollView by through UIScrollView, If you want to get UIScrollView you can use by this
var scroll = self.tableView as UIScrollView
//some code
Or you want to compare you can use
if scrollView == self.tableView {
//some code
}
I have UIView in my storyboard with outlet mynewView and i want it display with totally different content. And do it many times.
My UIView contains many objects, i load it from internet. But every time i do
NSArray *viewsToRemove = [view1 mynewView];
for (UIView *v in viewsToRemove) {
[v removeFromSuperview];
}
//Let's try to remove all possible views..
viewsToRemove = [self.view subviews];
for (UIView *v in viewsToRemove) {
[v removeFromSuperview];
}
//here i create mynewView
mynewView = [self createnewRandomView];
//And finally add the View we have created.
[self.view addSubview:mynewView];
i monitor the memory consumption and i see it grows every time i add new UIView. Even when i remove all superviews. I guess they remain in memory.
Before i change the view i remove from superview all possible views, but they still stay in memory.
Xcode is set to use ARC so i can't release it.
Is there any good way to reuse a UIView?
Thanks
[self.view addSubview:mynewView];
Your newView was added as subview of self.view.
Your above code does not use for remove yourVewView in self.view.
Please try this code before adding new view:
for (UIView *view in self.view) {
if([view isKindOfClass:[YourNewViewClassName class]])
{
[view removeFromSuperView];
break;
}
}
As you remove the subviews, set them to nil as you go, like so:
for (UIView *v in viewsToRemove) {
[v removeFromSuperview];
v = nil;
}
For more information, see for example Arc: Setting references to nil, for multiple buttons
i have success show subview from another NIB, i have 2 button and 1 UIView on MainView, when i klick button 1 will show NIB1 on UIView, and then i klick button 2 will show NIB2 on UIView, but when i klick again button 1 UIView not show NIB1 again, but still NIB 2, this is my Code :
Updated Solved
On .h file
IBOutlet UIView *bottomView;
On .m file
-(IBAction) handleButton1{
for (UIView *t in bottomView.subviews) {
[t removeFromSuperview];
}
if (![nib1 isViewLoaded]) {
nib1 = [[NIB1 alloc] initWithNibName:#"NIB1" bundle:nil];
}
[bottomView addSubview:nib1.view];
}
-(IBAction) handleButton2{
for (UIView *t in bottomView.subviews) {
[t removeFromSuperview];
}
if (![nib2 isViewLoaded]) {
nib2 = [[NIB2 alloc] initWithNibName:#"NIB2" bundle:nil];
}
[bottomView addSubview:nib2.view];
}
How i can refresh UIView with another NIB on my code ?
Thanks,
I have solve this case, i remove all subview on MainView from this http://stackoverflow.com/questions/3915729/refreshing-cell-content-after-deleting-cells
use :
for (UIView *t in bottomView.subviews) {
[t removeFromSuperview];
}
I hope this code help anyone :).
You have to remove the first view view [theViewYouDontWantToShow removeFromSuperview].
Or you can use [bottomView bringSubviewToFront:nib1/2.view].
What was appending here is only that you added a view (this works), added the other view on top of the first one (this works too), but then you added the first one again. The view doesn't change since it's already there.
I have a UITableView, under which (not in the header!) I would like a new UIView. It's done in WhatsApp, in the Chats' tab (I' new in here so I can't add a picture!).
Any help will be greatly appreciated.
Regards
Create a parent UIView to contain you UITableView and the other UIView. Add these views as subviews to the parent view.
Edited Answer:
You could do this. Initialize 2 buttons or 2 views in..
In the cellForRowIndexPath :
UIView * superView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 45)];
[superView addSubview:view1];
[superView addSubview:view2];
// You should make sure that CGRectMake of view1 + view 2 = superView //
Check if (indexPath.row == lastRow)
{
[cell addSubview: superView]
}
Original Answer:
You should use
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
I think the exact answer you are looking for is available here !!
UITableView has a backgroundView property that you can set.
What is the difference between addSubview and insertSubView methods when a view is added programmatically?
The only difference is in where the view is added: whether it is the frontmost view (addSubview:), or it is before the 5th subview, (insertSubview:atIndex:) or if it is immediately behind another subview (insertSubview:aboveSubview:).
Using insertSubView: you can specify the index, which determines z-order of views. A view with a higher index lies above those with lower indices.
I don't think there is a difference. addSubview: is simple a convenient method for
[view insertSubview:aView atIndex:[view.subviews count]]
1.addSubview add subview in array then add in View'slayer
- (void)addSubview:(UIView *)subview
{
[_subviews addObject:subview];
[_layer addSublayer:subview.layer];
}
}
2.While insertSubview add your view as subview then call
[_layer insertSublayer:subview.layer atIndex:index];
- (void)insertSubview:(UIView *)subview atIndex:(NSInteger)index
{
[self addSubview:subview];
[_layer insertSublayer:subview.layer atIndex:index];
}