Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring to avoid tight coupling #7

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion Beers/app/app_delegate.rb
Expand Up @@ -2,7 +2,8 @@ class AppDelegate
def application(application, didFinishLaunchingWithOptions:launchOptions)
@window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
tabbar = UITabBarController.alloc.init
tabbar.viewControllers = [BeerMapController.alloc.init, BeerListController.alloc.init]
beer_list_controller = BeerListController.alloc.initWithDetailsController(beer_details_controller)
tabbar.viewControllers = [BeerMapController.alloc.init, beer_list_controller]
tabbar.selectedIndex = 0
@window.rootViewController = UINavigationController.alloc.initWithRootViewController(tabbar)
@window.rootViewController.wantsFullScreenLayout = true
Expand Down
10 changes: 5 additions & 5 deletions Beers/app/beer_list_controller.rb
@@ -1,6 +1,7 @@
class BeerListController < UITableViewController
def init
if super
def initWithDetailsController(beer_details_controller)
@beer_details_controller = beer_details_controller
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Storing instance variables is not supposed to be done until after the if init check.

if init
self.tabBarItem = UITabBarItem.alloc.initWithTitle('List', image:UIImage.imageNamed('list.png'), tag:1)
end
self
Expand Down Expand Up @@ -33,8 +34,7 @@ def tableView(tableView, cellForRowAtIndexPath:indexPath)

def tableView(tableView, accessoryButtonTappedForRowWithIndexPath:indexPath)
beer = Beer::All[indexPath.row]
controller = UIApplication.sharedApplication.delegate.beer_details_controller
navigationController.pushViewController(controller, animated:true)
controller.showDetailsForBeer(beer)
navigationController.pushViewController(@beer_details_controller, animated:true)
@beer_details_controller.showDetailsForBeer(beer)
end
end
8 changes: 4 additions & 4 deletions Beers/app/beer_map_controller.rb
@@ -1,6 +1,7 @@
class BeerMapController < UIViewController
def init
if super
def initWithDetailsController(beer_details_controller)
@beer_details_controller = beer_details_controller
if init
self.tabBarItem = UITabBarItem.alloc.initWithTitle('Map', image:UIImage.imageNamed('map.png'), tag:1)
end
self
Expand Down Expand Up @@ -43,8 +44,7 @@ def mapView(mapView, viewForAnnotation:beer)
def showDetails(sender)
if view.selectedAnnotations.size == 1
beer = view.selectedAnnotations[0]
controller = UIApplication.sharedApplication.delegate.beer_details_controller
navigationController.pushViewController(controller, animated:true)
navigationController.pushViewController(@beer_details_controller, animated:true)
controller.showDetailsForBeer(beer)
end
end
Expand Down