last day (14 days later) » 

8:48 AM
0
Q: Close keyboard when view is pressed - Obj C

David BigaI have a function that populates a few fields into the self.view.window view. Now if I run: /* HIDE KEYBOARD WHEN CLICKED AWAY */ UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideKeyboard)]; gestureRecognizer.cancelsTou...

 
Why are you adding subviews to the window and not the view itself? The window should usually only contain your outer view and everything else should be nested inside it.
 
@timbodeit please check my update.
 
Is your view a UIScrollview or similar? If so try this: Take a regular view (#1) and add your scroll view as a subview(#2). Then add your date picker (#3) as a subview to #1 aswell. Apply the gesture Recognizer to view #1.
 
@timbodeit what is happening is I have a tableview that populates data. If a specific cell is clicked I populate data to the window because if there is to many cells your able to scroll which gives a break in the overlay on the window. Where as using the .window property does what i need it to do. I simply just need the gesture to recognize with when my cell opens the fields i dynamically populate.
 
Don't add tons of stuff to your window. Unless you are doing something really fancy, you should hardly mess with the window at all. Instead create a shared super view. And then you can obviously apply gesture recognisers at that level.
 
8:48 AM
@timbodeit couldn't I simply do a view.window?
 
That is not what the window is for. You could theoretically do that, but it is bad design.
Your application only has one window. And that is where you put all your content. The way it is usually done is this:
You create a view controller that has a view (and really only ONE view at the top level). This view is added to the window.
 
Okay well I figured it out also
 
Every other element the viewcontroller needs to show on the screen gets added to its single view.
 
I simply added it when I click on a cell I use
[self.view.window addGestureRecognizer:self.gestureRecognizer];
What would be the best approach to this?
 
3
A: How to dismiss keyboard when an UIControl is touched?

Kirit ModiYou Touch code is correct but it also working fine in my code.when you click outside of text-field at that time Touch event call but its inner condition is not working good.i remove the condition and check its working fine. - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [...

 
8:52 AM
You are probably using a tableviewcontroller right?
 
Yes
 
The problem a UITableViewController has is, that its root view is already a tableview. And you can't add any more custom UI to it.
 
runs an api script to my server, returns json data
populates cells
I listen for when a cell is clicked
and do what I have to from their
I have an overlay method that puts the overlay in view.windo
only for the purpose of giving it a fixed like style because I couldnt figure a better way to do it.
 
You circumvent that by just adding your remaining UI to the window. While this works, it shouldn't be done this way.
 
Please enlighten me
view.window
 
8:55 AM
Instead use a regular UIViewController. This will have a regular UIView as the root view.
Then add a tableview as a subview to it.
How to make the tableview work in a regular UIViewcontroller, have a look here : stackoverflow.com/questions/9763028/…
Then add everything to the root view, that you would otherwise have added to the window.
 
oh ya
I was doing that for my other project
no idea why I did not do that for this
I just used a straight up UITableView
 
Your current structure:
- UIWindow (you only get one of these per app):
- Your other UI 1
- Your other UI 2
- tableView
Ok, chat apperently doesn't indent
 
Its okay
Yes I see what your saying now
thanks
 
Just a quick though: What really the problem with adding to the window is: When you present another viewcontroller, all of the things that you add to the window are still there
And they will be on top of everything else
 
well no
because i am using the .window for more of an action or alert purposes
I remove those based on an action
an action has to execute before anything else would happen
either action will remove those views
So for instance, I have a pay form for stripe
I have either cancel or pay
they add all their card information there and click either pay or cancel
either case, those views are all removed using removeSuperView
 

last day (14 days later) »