Adding UITableView to subview when searchbar is being edited - iphone

I have a MKMapView with annotations on it and it works fine. I have a search bar as part of my navigation bar. When a user clicks on the search bar field I wanted to bring up a UITableView in code. I create a UITableView in the initialisation and want to add it to the sub view when - (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar; gets called.
This all works fine but im trying to add it using [self.view addSubview:tableView] and nothing shows up. I've only ever made table views using UITableViewController so I'm a bit lost.
Thanks

I'd suggest creating a UITableViewController to control it, and then using presentModalViewController:animated: to show the tableview.

This was actually correct. I was just initialising it wrong not setting the bounds for it.

Related

Making a UITabView show the second level of a navigation controller by default

(Apologies for not being able to embed my images yet).
Using iOS storyboards, I have a UITabBarController with a UINavigation Controller/UITableView(1) embedded in it. This UITableView(1) then calls another UITableView(2):
What I'm trying to do is to make UITableView(2) appear when the Tab Bar is changed to that tab, and then have the UINavigationBar left arrow button exist to get back to UITableView(1).
The existing functionality I can think of which does this is the iPhone Mail app, where when you launch it you see your Inbox, and you can hit the left-arrow Mailboxes button to get back to your mail box list.
I've tried attaching the tab bar directly to UITableView(2) but it doesn't work as expected, there's no left arrow back button to get back to the previous view when the app is run.
I've also tried adding a navigation controller to that UITableView(2) and the Navigation controller correctly appears, but still without any back button:
Any suggestions as to what I'm doing wrong would be greatly appreciated, I'm fairly new with storyboards and it's difficult to find what to search to get this working.
If it's not possible with just storyboards themselves, is there some kind of automatic (non-visible) push to the 2nd UITableView I could do?
Thanks!
Nick.
This tutorial will definitely help you : http://maybelost.com/2011/10/tutorial-storyboard-in-xcode-4-2-with-navigation-controller-and-tabbar-controller-part1/
I ended up implementing it the following way, as I wanted to perform the majority of the work within storyboards.
I set up the storyboard with the tab bar embedding the UINavigationController, which contained UITableView(1) which then contained a custom segue to UITableView(2):
Then within the class associated with UITableView(1) I added this single line:
- (void)viewDidLoad {
[self performSegueWithIdentifier:#"campaigns" sender:self];
...
}
On load of the tab, the viewDidLoad of UITableView(1) instantly calls UITableView(2) without any kind of animation, showing the back button to UITableView(1), which is exactly what I wanted.
Thanks to those who responded!
You can implement the delegate method as below.
(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
In this method you can check for the tabBarController.selectedIndex or viewController object. This ensures the selection of correct tab , then push the controller having table 1, then push the controller having table 2.

How to freeze a bar in a UItableview

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.

Scrollable all the way UITableView

I have this code linked to a button on a ViewController with a UITableView as subview:
-(IBAction)Action:(id)sender{
[tableView setContentSize:CGSizeMake(320, 1000)];
}
This makes tha tableView scrollable to the bottom so that I can use a couple of buttons I programatically added to the bottom. So far so good.
However, I want the tableView to be ok from the beginning, so I added the code inside viewDidLoad. Surprisingly, it doesn't work at all.
Could somebody give me a hand?
thanks!
If your datasource methods are being fired after viewDidLoad, the tableView content size will be reset when it's loaded. You'll need to make sure you've called reloadData for the table before the code above. If you're using a UITableViewController, the order the methods are called is:
viewDidLoad
ViewWillAppear:
<your datasource methods>
ViewDidAppear:
However, if you want buttons at the end of table, you should put them in the tableFooterView. You can do this in interface builder easily by dragging a view to the bottom of the tableView. Or you can do it in code (in your viewDidLoad method, for example)
Per #Justin's answer... your question isn't very clear
I'm not sure what your trying to accomplish. If your trying to access button on the bottom of a tableView why not use a Tableview Footer.
And if your trying to just scroll to the bottom of the tableview there is a method for that as well.
Need more info

Making a tableviewcell scroll up on displaying keyboard

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.

UISearchaBar is disappearing from UITableView

I've a view controller (named it as SearchViewController) with UITableView and UISearchBar. UISearchBar is set to table as a header view. While searching in the table using this searchbar works great.
By selecting any one of the displayed search results, I can move to next view (named it as DetailsViewController). But after returning to the SearchViewController, magically the UISearchBar is disappeared and my app is crashed. I found the same code is working fine on iOS 3.1.2 but not on iOS 4.0 (no idea about 4.0.1 or 4.0.2).
I'll be really thankful, if anyone has a work around for this.
I always use an UINavigationBar and an UINavigationItem to display the UISearchBar. Setting the navigationItem.titleView to the searchBar works fine for me. (Don't forget to call [theSearchBar sizeToFit])
Please give us more information on the crash. What is the console output?