0

I've done some searching that hasn't helped me find the answer I am looking for.

My app has a UITabBarController which allows the user to switch between screens.

There are two screens

Tab1: viewController A - which is a subclass of UIViewController. It has a UiSearchBar at the top and other non-related content below.

Tab2: viewController B - is a subclass of UITableViewController and also conforms to the UISearchBarDelegate and UISearchDisplayControllerDelegate.

This view has a UISearchBar and DisplayController at the top.

The is what I want to get working in my app:

When the user starts a search in viewController A - some results will show below the search bar. Then, when the user taps a search result then viewController B will appear on screen and show the results. This will allow me to filter and arrange results as I see fit.

If anyone has seen the latest version of the eBay iOS app - the searching function is what i am trying to get working.

*The Problem *

I am not worried about how the search works and how filtering works, etc. What I want to know is how do i link the first UISearchBar to display results and take the user to viewController B - with their search terms?

If I look at eBay app - its almost like the bar is the same instance as it keeps the search text.

If anyone can point me in the right direction, I'd really appreciate it.

Thank you!

Robert J. Clegg
  • 7,231
  • 9
  • 47
  • 99

2 Answers2

0

I would: write a protocol XYZ in your UIViewController A

Subclass your UITabBarController and make it conform XYZ

After user presses a search result in UIViewController A, send the delegate (your UITabBarController) a message and let him handle the data (array of your search objects or whatever you need) transfer and switching to UIViewController B

Have a look at this Q on SA about transferring data between UIViewControllers: Passing Data between View Controllers

Community
  • 1
  • 1
Jasper
  • 7,031
  • 3
  • 35
  • 43
0

Passing data between controllers works fine for simple programs but I find it gets confusing as the app becomes more complicated. Another approach is to create a real data Model…the 'M' in MVC.

The primary model class that gives access to application state can either be a singleton with a sharedInstance or a unique object that's owned by the app delegate. With that structure, there's no passing of data directly between controllers. Instead, any controller that needs to change state tells the Model to do so and any controller that needs to know state asks the Model for it when displaying or updating views.

Phillip Mills
  • 30,888
  • 4
  • 42
  • 57
  • The app gets 99% of its data from web services. I have a singleton class for the model already - which executes websevices and allows me to access persistent data that I need. Passing data from view to view I am using segues and unwind segues mostly. I will look into other options too. Thank you – Robert J. Clegg Mar 06 '14 at 13:32
  • With the data model approach, you still use all the same navigation logic (segue…). The main difference is that controllers aren't dependent on each other for what to display; they react independently to changes in application state. – Phillip Mills Mar 06 '14 at 13:36