Reloading the view when row changed in tableview objective c - ios

I have done markup code for different images. When the image changes, the markup and button still remain on screen. only it changes when i make a new markup on it.
The below image shows the button and markup of beach image.
Please help me...

You might be using viewController.view instead of inhering UIView.
So now you can call a viewcontroller's instance method on didSelectRowAtIndexPath event, which will clear all the widgets from the existing view.
- (void)clearSubviewsFromContainerView
{
for(UIView *view in [containerView subviews])
{
[view removeFromSuperview];
}
[self createNewWidgets];
}
Then call another method to generate and load new widgets.
- (void)createNewWidgets
{
// add new buttons, images over here in the same container view
}
Hope this might help you out.

Related

How to remove view on touch?

I have a button hooked up in the storyboard to a method onButtonPress. In that method I call [pressedButton removeFromSuperview] but the view is not removed. I have even tried [_scrollView setNeedsDisplay]; and [_scrollView setNeedsLayout]; with no luck. I am assuming this is a restriction on being able to remove the button I have pressed. Is there a way I can signal to the view controller to call a method in the future to remove this button?
you can just hide it,
- (IBAction)celebritiesButtonPressed:(id)sender {
self.button.alpha = 0;
//[self.peopleButton removeFromSuperview]; //as you intend
}
Nevermind, actually. I was making a silly mistake.
The view I was pressing is part of a custom table I implemented to avoid the tableview in the scrollview. What I was doing was removing all the table cells from the table then re-adding them with the exception of the one that was clicked. Except right before I looped through the array which held the views and called [view removeFromSuperview], I removed the view I pressed from that array. Therefore, it was never calling that method.
So I was doing
[_taskViewCells removeObject:t];
for (id taskViewCell in _taskViewsCells) {
[taskViewCell removeFromSuperview];
// Remove all the task views
}
Pretty silly...

Spinner on top with many other `UIView`

I'm trying to find why my spinner is not visible.
I have a custom UIActivityIndicatorView. I want to put it on the top of my custom UITableViewCell.
Here is my code:
[downloadingSpinner startSpinner];
Where startSpinner is
- (void) startSpinner{
[self setHidden:NO];
[spinner startAnimating];
}
When I call this startSpinner method, I can't see my spinner. I directly tried to solve my problem with this code:
[self.cellView bringSubviewToFront:downloadingSpinner];
Where cellView is the main view of my cell.
I also tried this code:
downloadingSpinner.layer.zPosition = 1000;
I finally checked the subviews of my main view (cellView). I can see 14 views and le 13th is my custom spinner.
I tried to change the order on the storyboard like this:
I don't have any other idea to put this spinner on top.
I simply add
[self.cellView bringSubviewToFront:downloadingSpinner];
just after I've added my custom UIScrollView. Thank you for your help and I hope this will help someone else.

ios display views and viewcontrollers on part of the screen

I have this bug that I'm struggling with for a few days now. I basically want to make a profile much like Instagram has.
When you click on one of the first two buttons in the upper "tab bar" the content is displayed in the lower part. The upper part of the screen stays the same. I have some UIViewControllers and some UITableViewController. I have like 5 buttons that are suppose to display the viewcontrollers. My problem is that I can display a tableviewcontroller but if I try to display the second and then go back to the first, for instance, it gets stuck to the last one I displayed. I hope this is clear enough. here is the code for displaying the viewcontroller.
- (IBAction)wallButtonPressed:(id)sender
{
if(!_userWallViewController) {
self.userWallViewController = [[WallViewController alloc] init];
self.userWallViewController.activityFeedTableView.bounds = self.containerView.bounds;
}
[self.currentViewController.view removeFromSuperview];
[self.currentViewController removeFromParentViewController];
self.currentViewController = self.userWallViewController;
self.userWallViewController.searchURLString = [NSString stringWithFormat:#"/event/user/%#", self.userID];
self.userWallViewController.containerView = self.containerView;
[self.containerView addSubview:self.userWallViewController.view];
[self addChildViewController:self.userWallViewController];
[self.userWallViewController.view setNeedsDisplay];
[self.userWallViewController viewWillAppear:YES];
}
containerView is an UIView that takes the whole lower part of the screen. currentViewController is a placeholder viewController and userWallViewController is a UITableViewController.
Any kind of help is much appreciate. This is a real bugging situation. Thanks
I was doing a stupid mistake that was hard to identify bu #Matt's suggestion helped.
[self.fanOfViewController.containerView addSubview:self.fanOfViewController.userSimpleTableView];
[self.currentViewController.view removeFromSuperview];
[self.currentViewController removeFromParentViewController];
self.fanOfViewController.containerView = self.containerView;
[self addChildViewController:self.fanOfViewController];
[self.containerView addSubview:self.fanOfViewController.view];
//CLEAN UP THE CONTAINER VIEW BY REMOVING THE PREVIOUS ADDED TABLE VIEWS
[self.userWallViewController.activityFeedTableView removeFromSuperview];
[self.userFansViewController.userSimpleTableView removeFromSuperview];
Each time I was adding a new tableView from it's view controller by pressing the corresponding button I was stacking it in the current's view container. When I was trying to remove the corresponding viewController from the hierarchy and then add it again the viewDidLoad method was not called (it was only called the first time). The was where I had my logic of removing the tableView.
Now I'm also adding it when the button is pressed and remove the other tableViews from the "stack". It may not be the very best way but I do plan to optimize it. I hope this is clear enough and helps anybody that comes across this problem.

Reordering UIView subviews

In my app I am trying bring a subview to front, then put it back to its original layer position later. The code should be pretty simple:
To bring the subview to front (inside my custom UIView class):
[self.superview bringSubviewToFront:self];
Easy. I store the original z position in an instance variable called, you guessed it, zPosition. So, the line before -bringSubviewToFront: is:
zPosition = [self.superview.subviews indexOfObject:self];
So, all of the code I use to bring my subview to front is:
zPosition = [self.superview.subviews indexOfObject:self];
[self.superview bringSubviewToFront:self];
This works as it should. The problem is when I try to put the subview back where it was. I'm simply doing this:
[self.superview exchangeSubviewAtIndex:zPosition withSubviewAtIndex:
[self.superview.subviews indexOfObject:self]];
Using this code, if I have two subviews, this is what happens:
Let's say I have view A and view B. View A is above view B. I tap view B, it comes to the front. I tap view B again (it should go back to where it was), and nothing happens, so it's now on view A. If I now tap view A, it comes to the front, but when I tap it again (so it should go back to its original z position: below view B), all of its sibling views disappear!
Does anyone see what could be causing this problem?
There is no need to remove from superview:
[self.superview insertSubview:self atIndex:zPosition];
exchangeSubviewAtIndex may well put the view back in the right place, but it will also swap another view on top, which wont be what you started with. You might need to do something like this instead of exchangeSubviewAtIndex :
[self retain];
UIView *superview = self.superview;
[self removeFromSuperview];
[superview insertSubview:self atIndex:zPosition];
[self release];
[ Swift solution ]
As other guys said, there is no need to remove and re-add your subviews.
Instead I've found that the most convenient method is:
superView.insertSubview(subviewYouWantToReorder, aboveSubview: subviewWhichShouldBeBelow)
This question and answers were very helpful to me.
I had the requirement to place an overlay between the viewstack which views are above and below the overlay, and i wanted to keep it dynamic.
That is, a view can tell it is hidden or not.
I used the following algorithm to reorder the views.
Thanks to AW101 below for the "No need to remove view".
Here is my algorithm:
- (void) insertOverlay {
// Remember above- and belowcounter
int belowpos = 0, abovepos = 0;
// Controller mainview
UIView *mainview = [self currentMainView];
// Iterate all direct mainview subviews
for (UIView* view in mainview.subviews) {
if ([self isAboveOverlay:view]) {
// Re-insert as aboveview
[mainview insertSubview:view atIndex:belowpos + (abovepos++)];
}
else {
// Re-insert as belowview
[mainview insertSubview:view atIndex:belowpos++];
}
}
// Put overlay in between above and below.
[mainview insertSubview:_overlay atIndex:belowpos];
}

ios custom navigation (vertical) advice

I have an idea for an ios5 navigation I'm doing on an app and I thought it wise to get some constructive criticism from SOF about my idea.
Idea:
UIView containing 6 or so buttons stacked vertically
UIButtons have a selected state.
Buttons static/global keeps track of last touched button and always resets the last touched button when a new UIButton is touched.
Question:
Can you read and access the children of the UIView?
eg. (pseudocode)
for (i in [myView children]) {
[[myView getChildAt:i] doSomethingToThisButton];
}
Thanks all!
Yes. Here's the non-pseudocode (well, mostly):
for (UIView *subview in [myView subviews]) {
[subview doSomethingToThisButton];
}
Or, if you prefer
for (int i = 0; i < [myView.subviews count]; i++) {
[[myView.subviews objectAtIndex:i] doSomethingToThisButton];
}
Don't make your last touched button a static variable because then you can only have one such control in your whole app. Make a UIView subclass to act as the container for your buttons, and have the last selected view be a property of that class.
You may also want to make your containing view a subclass of UIControl instead of UIView, then you can make it send events and bind to it using drag and drop in interface builder, just like a regular control (e.g. a button).

Resources