.hidden = YES working but .hidden = NO not working - ios

I have a UIImageView with a custom class in a table cell that also uses a custom class. The UIImageView is connected as a property of the cell's custom class.
The UIImageView has a UITapGestureRecognizer that calls method tapped: I'm passing the cell as the UIImageView's delegate and trying to unhide another view of cell using cell.theOtherView.hidden = NO Strangely, to hide .hidden = YES works, but to unhide isn't working.

It's hard to know what's going on without seeing the code you're working with (for example, your code might never actually be reaching the line that sets the view to be hidden), but as MattyAyOh suggested, it's worth trying
[cell.theOtherView setNeedsDisplay];
after you set cell.theOtherView.hidden = YES;. This will force the view to redraw itself.

My guess is that once it's hidden, it no longer received the Tap gesture. Try using cell.theOtherView.alpha = 0.0.

you should register your object to .h file first, then you could use hidden function

Related

UIButton default tap animation inside UITableViewCell

I have a few UIButtons inside UITableViewCells, and all of them are missing default tap animation, however if I long press - animation works. I've found some solutions, like setting type to .system, showsTouchOnHighlight = true, but none of them have helped. What is the problem here?
It's not a "problem" - it's by design.
When you have an object such as a button in a table view or scroll view or collection view, and you "touch" it, the system needs to know whether you are tapping the button or if you want to touch-and-drag to scroll the view that contains the button.
So, the table view (really, the "scroll view part" of the table view), waits to see if you drag your finger or not before it performs any actions.
If you want the button to respond immediately to a touch, you need to set
delaysContentTouches = false
on the containing scroll view(s).
If you search for uibutton inside uitableviewcell delaysContentTouches you should find plenty of discussion on this topic, and various approaches to change the default behavior.
For this problem you can add extension to UIButton and override some methods.
You can check my answer here

Making a UIView receive events after showing it (setting hidden = false)

I already tested the solution of setting up the alpha property from 0 to 1. However, this seems to be performance intensive operation.
What I want to do to make the UIView receive the touch events after showing it back by setting hidden = false
Is there a way to do that? I thought calling .becomeFirstResponder would solve this with no luck.
Yes, The first thing is mention by #wltrup that you have to enable userInteraction property of that view by this:
view.userInteractionEnabled = true;
and another is you have to add proper gesture recognizer on that UIView to perform specific events.

How do I show and/or hide a subview using swift

So I've created a ViewControl in my storyboard that has 3 subviews. Each one represents a different view I want to show depending on which table row was selected on the previous screen (NavControl). I start with all of the subviews hidden via the Attributes Inspector's 'hidden' attribute being checked. All of the objects within each of these views are NOT hidden, but are being hidden because the subview itself is hidden (obviously). Thinking I could use the tag attribute I've given each of the three subviews a tag (0, 1 and 2), but can't figure out how to use that either (just in case this is useful as providing me with an option of how to do this I wanted to mention it here).
So, how the heck do I show and then hide any of these subviews? I don't want to go through each object in a subview and toggle its hidden property to true/false I feel like I should just be able to 'show/hide' the entire subview. thus achieving the same result, but much more succinctly.
I can't find anything that will help me via web searches or stackoverflow searches.
My code is very simple. I capture the row that was selected in the previous screen and pass it to a variable on the details screen that contains the subviews. I know this is working because I've set up println()'s on the details screens viewDidLoad function. So now all I have to do is going into each of these conditions and tell it which subview to show and/or hide.
Thanks I appreciate all of this communities help! I'd be lost without it.
Use this to hide a view in swift
viewVar.isHidden = true
You should create IBOutlets for each of the three subviews. Then you can show/hide each of them directly from those references. If you hide a view, it will automatically hide its subviews.
Once you have an outlet for the view, you can do this:
viewYouWantToHide.isHidden = true
If you have tags for each view you can hide and display them using:
Objective C
For Hiding:
[[self.view viewWithTag:1] setHidden:YES];
Showing:
[[self.view viewWithTag:1] setHidden:NO];
In Swift:
Hiding:
self.view.viewWithTag(1)?.isHidden = true
Showing:
self.view.viewWithTag(1)?.isHidden = false
NOTE: Replace 1 with your tag value.
however the fact that isHidden is a naming convention for checking the status and is a getter method
but despite that fact in swift we use it as setter and getter property
view.isHidden = true

Issue with overlapping text: iOS7

I normally post source code and examples of UI but I think its more related to an iOS7 change and I cant see it being a code bug (yet). I would have to post so much code and UI that it would be counter productive. So here is my best non-visual description:
Since upgrading a project to iOS7 I am finding that if I put call to change a UILabel or calling setText of a UIButton in a ViewDidAppear or ViewWillAppear it puts the new text right on top of the old text.
Since developing for iOS I have never had to do anything different. If I do this:
lblMyHours.text = #"12";
It shouldnt just throw that on top of my existing label.
This especially happens inside of a UITableView where I have created an iVar for a UILabel thats in a UITableViewCell. If a user makes an adjustment to a value after clicking on a cell (it takes them to a detail screen to edit), when I pop back I have it recalculate in ViewDidAppear. In that recalculating I am resetting a label like the above. But it doesnt clear out the old.
You might be adding a new label every time you return a new cell.
You should just replace the text of the current label instead.
There are two way to achieve this, one you are already doing and as #Guilherme rightly pointed out. The other way is to create a custom tableview cell and put the UILabel property in there. As for the viewDidAppear scenario, you can create a uilabel in ther .h file (in the #interface declaration) and then initialize it in ViewDidLoad method and simple use in ViewDidAppear method without having to declare it again.
I would suggest that you follow the way I described for ViewDidAppear issue, and for the UITableView issue, search for UILabels in subview of the cell everytime cellForRowAtIndex method is called and remove it from the subview, something like this before adding a new label
for(UIView *view in cell.subviews)
{
if([view isKindOfClass:[UILabel class]])
{
[view removeFromSuperview];
}
}
Hope this helps.

iOS - How To Make my view so that it doesn't respond to events

i have asked this question Changing UIView To be instance from UIControl Programmatically 24 minutes ago but i he didn't benefit me , so i typing this question in another form hoping that you can help me
i have a view that its class is from UIControl (so of course it will receive events)
and i have a button that i want it to change my view to normal UIView instance (so of course it will receive events)
so how to make that
i want the code if changing the view to UIView here
-(IBAction)pauseButton:(id)sender
{
//here
}
i want the code of changing the view to UIControl here
-(IBAction)playButton:(id)sender
{
}
Firstly make sure you have an IBOUTLET for that view or object and make sure it is connected.
For example we will say the view is called the_view
Now you can over uncheck the UserInteractionEnabled checkbox within the interface builders property tab of that object or type a line of code. The second option is better if you want the button to raise the event of stopping touches being allowed.
For the first option I have uploaded a video showing the basic steps:
Click Here For tutorial
For the second on option you can use this code:
the_view.userInteractionEnabled = NO;
Or if you are trying to hide your default view simply use:
self.view.userInteractionEnabled = NO;
or as noted in the answer above:
[self setUserInteractionEnabled:NO]
You can not change an object's class in objective-c. If you just want the control to stop receiving touches, you can use:
[self setUserInteractionEnabled:NO]

Resources