I have seen this question posted several times with no useful answers. I am trying to place a toolbar above my UIKeyboard in my iPhone app, but am having difficulty. I found this example which works GREAT, except that my view is a UITableView instead of the standard [self.view addsubview:...]. Can anyone figure out how to apply this to a UITableView?
In short, I have several UITextFields in my table cells, so I want the toolbar to appear above the keyboard for those cells.
Many thanks,
Brett
Just don't use the table view directly as a view.
Use a view that will have a table view inside it.
This way you will be able to use the tutorial as is...
In my opinion this way is much better - I don't have view controller with a single table view in any of my applications. There is always something additional on the screen...
In addition, I don't think that using parentViewController is good solution.
Not always you have one.
Actually, I don't even understand how it works for you...
A work around for this would be to create a hidden textfield in a viewcontroller and present it modally with it begin the first responder. The view can be completely transparent and the toolbar can be configured using the interface builder.
Related
I am making an app and would like to direct my user once they log in into their dashboard, I have seen some apps display things in what seem like a table view controller or a view controller with a table view. I would like to display the logo up top and then a table displaying their username then about 4 more rows displaying other info then at the bottom a tab bar. What would be the best way to go about this?
any advice welcomed. If relevant I am using swift, Xcode7 and parse to handle my users
Use a UITableView. This a bit more customizable in terms of Storyboard layout. You can place UIImageViews, toolbars, and other elements all over your UIViewController. You can then put a UITableView in the exact place that would work for you, with the dimensions you need.
Of course, you could always use a UITableViewController. You could embed this controller in a variety of combinations, which would let you add tab bars or navigation bars.
The only real difference in implementation is that you have to remember to explicitly write the delegate and data source methods when using a UITableView.
For your case, I would pick whatever seems easiest to implement in your case. Probably a UITableView in my opinion.
Some differences between UITableViewController (TV) and UIViewController with TableView (VT) I know:
You can add other controls into VT and pin it to anywhere you want. TV can't do that.
You can add many same group of controls without add constraints with TV. VT you have to add constraints.
You don't want to worry about scrolling in TV with many group of controls.
With TV you can create static table cell but you can't with VT. Static table works on TableViewController only.
In your situation, I use UITableViewController with static table to achieve that.
Hope this can help.
As in the screenshot 1, I am trying to design view that is longer then screen size of iPhone.
and in second screenshot I changed the size to freeform which is giving me liberty to create longer view than iPhone's length.
My question is is it a standard way to solve this problem. where as my understanding was that we are not suppose to use xib files anymore after storyboard because every thing was moved to storyboard.
So to solve this this problem Do I have to use view(xib) and make it as subview of UIscroll view.
is that a standard way to solve these kind of problems or do we have something with storyboard equivalent which is more efficient ?
PS: I have been researching this problem from past few days. All related questions over here and web, are adding UIView programmatically to ViewController but not a single example I found where one is designing the UIView in Xcode thru xib file and adding it to UIScroll View. Which is common real world problem. all the app where views are longer or wider than screen size are not done programmatically all together. At least I think they are being designed and them added to the Viewcontroller. Please correct me If I am wrong.
The answer is, as it's always been on iPhone, modal views which come and go as needed. You can temporarily add child view controllers, alert views, 3rd party iphone compatible popover knockoffs....
Of course UIView still exists - so where is the problem? What you probably mean is that you cannot set an UIView in a storyboard, storyboards only contain view controllers. But you can still make a xib file containing an UIView of any size you like, and add that one to your scroll view.
I've made a custom class that consist in a customized animated toolbar instanced in all my views. It works well in classic UIview using [view addSubview:]. The bar stays between the tabbar and the view. But in my tableviewcontroller, it follows the cells when I swip them.
I don't have Xcode right here so I can't post any explicit code, but I'm just looking for a hint.
Thanks
PS: I've tried to search it over stack and Google, but I think I use the wrong keywords (not so good english :p)
Which view did you add your bar?
Try add it to the superview of the tableview instead of tableview itself.
Before Starting I want to make sure one thing whether we can make the ViewController transparent (alpha), as far my knowledge it is NO.
I have a ViewController which consists of 8 UIButton objects over it. Whenever I press Button1, Button2 I am loading a ViewController. Since the ViewController cannot be made transparent, I just moved that View to my HomeViewController.xib and I am loading the view using -addSubView:. And I am changing the alpha value to make it as transparent.
But the thing is in Button1 View and Button2 View, in both views I am having table view. When I bring everything to the same HomeViewController class , I am having too much of code in a single class.
Is there any way to do this?? Adding many Views in the same ViewController not a problem, but it increases the code too. Which looks ugly. Please help me out.
If I have confused about my question here I am giving a short description of what I would like to do
Whenever I press a Button in ViewController, I want to load a View/ViewController Transparently.
Before Starting I want to make sure one thing whether we can make the
ViewController transparent (alpha), as far my knowledge it is NO.
You can't adjust a view controllers alpha directly. You can adjust a view controllers view properties alpha, ex: myViewController.view.alpha, and you can do this for any view that you want except for your root view (the bottom of the view stack). Lowering your root views alpha would allow the user to see the springboard through your app.
But the thing is , In Button1 View and Button2 View , in both views I
am having table view. When I bring everything to the same
HomeViewController class , I am having too much of code in a single
class.
Is there any way to do this ?? Adding Many Views in the same
ViewController not a problem, but it increases the code too. Which
looks ugly. Please help me out.
I'm not sure I understand the problem here. As long as you format your code correctly and keep well organized this isn't a problem. I personally have used view controllers in excess of 15k lines of code and never had a problem, and I'm sure there are developers that have used way more.
If I have confused about my question here I am giving a short
description of what I would like to do Whenever I press a Button in
ViewController , I want to load a View/ViewController Transparently.
Continue the way you have been describing. (adding alpha adjusted UIView's as subviews) There is nothing wrong with this approach.
I have a UITableViewCell with UITextField. In the edit mode, when the keyboard comes up, the row I am trying to edit gets overlapped by the keyboard. Ideally the row should scroll up so that I can edit the cell.
I have searched stackoverflow throughly and found several different solutions. Most of them has to do with calculations to move or scroll the view up. Now there is a sample code from apple called TaggedLocations. They have the exact same behavior. And there is no code doing any complex calculations to move the view up.
I also thoroughly checked the IB interface and could not find any fancy thing going on either. If you download and run the code, it beautifully pushes up the row to a perfect position for the edit.
Does anybody know what trick is there in the TaggedLocations project which does this so elegantly? Location of the project:
http://developer.apple.com/library/ios/#samplecode/TaggedLocations/Introduction/Intro.html%23//apple_ref/doc/uid/DTS40008914
For the complex calculations I was referring, look at the following thread for example:
How to make a UITextField move up when keyboard is present?
thanks
This line in RootViewController.m is what causes the scroll:
[self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:YES];
Put that in your cellForRowAtIndexPath: method and it should work.
I figured out the problem.
Initially I had
TabBarController
- UIViewController
-- UINavigationController
--- UITableViewController
- UIViewController
- -UINavigationController
--- UITableViewController
With this kind of a hierarchy the table cells do not roll up when keyboard is displayed. But if I change the hierarchy to the following the rolling up happens just fine without any additional code!
TabBarController
- UINavigationController
-- UITableViewController
- UINavigationController
-- UITableViewController
When I duplicated the Apple code, I somehow messed up the hierarchy. Now on switching to the new hierarchy, it works fine.
No additional code or calculation necessary.
or call viewWillAppear if you have your own hierarchy of controllers... then table views will automatically scroll cells to be visible when keyboard appears.
I had a similar confusion with Apple's sample code TaggedLocations, although in my case I realized that my table view was being managed by a UIViewController subclass as opposed to a UITableViewController subclass, and UITableViewController apparently manages the scrolling for you. It works quite well, so a lot of these complex calculations are unnecessary. I wish I didn't spend so much time trying to figure them out.
I don't see why the hierarchy you describe would matter. As long as the UITableViewController is managing the text fields, it should automatically take care of the scrolling to avoid the keyboard.