Skip to content

Commit

Permalink
Change UITableViewController cell segues to be automatic rather than …
Browse files Browse the repository at this point in the history
…manual
  • Loading branch information
thoughtadvances committed Mar 4, 2013
1 parent e31e3d5 commit a08e5dc
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 43 deletions.
26 changes: 14 additions & 12 deletions FlickrExplorer/FlickrPhotoSelectorTableViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
// Copyright (c) 2012 ThoughtAdvances. All rights reserved.
//

#import "FlickrPhotoSelectorTableViewController.h"
#import "FlickrPhotoViewController.h"
#import "FlickrFetcher.h"
#import <MapKit/MapKit.h>
#import "MapViewController.h"
#import "FlickrPhotoAnnotation.h"
#import "SegmentedViewController.h"
#import "FlickrPhotoSelectorTableViewController.h" // self
#import "FlickrFetcher.h" // Flickr dictionary keys
#import <MapKit/MapKit.h> // annotation creation
#import "MapViewController.h" // segue
#import "FlickrPhotoViewController.h" // segue
#import "FlickrPhotoAnnotation.h" //
#import "SegmentedViewController.h" // ipad view switching

@interface FlickrPhotoSelectorTableViewController ()
@property (nonatomic, strong) IBOutlet UIActivityIndicatorView* spinner;
Expand Down Expand Up @@ -174,19 +174,21 @@ - (void)fetchThumbnailForPhoto:(NSDictionary*)photo
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
self.selectedPhoto = [self.photos objectAtIndex:indexPath.row];
if (self.splitViewController) {
NSDictionary* selectedPhoto = [self.photos objectAtIndex:indexPath.row];
if (self.splitViewController) { // ipad
id detail = [self.splitViewController.viewControllers lastObject];
[detail changeToViewControllerNamed:@"PhotoViewController"];
detail = [detail getViewControllerWithID:@"PhotoViewController"];
[(id)detail setPhoto:self.selectedPhoto];
} else [self performSegueWithIdentifier:@"showPhoto" sender:self];
[(id)detail setPhoto:selectedPhoto];
}
}

#pragma mark - Other view controllers
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"showPhoto"]) {
[segue.destinationViewController setPhoto:self.selectedPhoto];
NSIndexPath* indexPath = [self.tableView indexPathForSelectedRow];
[segue.destinationViewController
setPhoto:[self.photos objectAtIndex:indexPath.row]];
}
else if ([segue.identifier isEqualToString:@"showMap"]) {
[segue.destinationViewController setAnnotations:[self mapAnnotations]];
Expand Down
29 changes: 17 additions & 12 deletions FlickrExplorer/ViewControllers/FlickrPlacesTableViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@
@interface FlickrPlacesTableViewController ()
// TODO: Create a custom data Class TACountry which stores this more easily
// Flickr countries presented in the table view

// sorted Flickr places ready for display
@property (nonatomic, strong) NSArray* sortedPlaces;
@property (nonatomic, strong) NSDictionary *selectedPlace;
@end

@implementation FlickrPlacesTableViewController
- (void)setPlaces:(NSArray *)places { // sort new places into sortedPlaces
_places = places;
self.sortedPlaces = [FlickrPlacesTableViewController
makeArrayOfPlacesByCountry:self.places];
makeArrayOfPlacesByCountry:self.places];
}

- (void)setSortedPlaces:(NSArray *)sortedPlaces { // display new places
Expand Down Expand Up @@ -198,23 +198,28 @@ - (UITableViewCell *)tableView:(UITableView *)tableView
return cell;
}

#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:
(NSIndexPath *)indexPath
{
- (NSDictionary*)placeAtIndexPath:(NSIndexPath*)indexPath {
NSDictionary *country = [self.sortedPlaces objectAtIndex:indexPath.section];
NSArray *places = [country objectForKey:@"places"];
self.selectedPlace = [places objectAtIndex:indexPath.row];
// This segue must be manual because otherwise the segue is called
// before the indexPath is updated
[self performSegueWithIdentifier:@"PlacePhotos" sender:self];
return [places objectAtIndex:indexPath.row];
}

#pragma mark - Table view delegate
//- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:
//(NSIndexPath *)indexPath
//{
// // This segue must be manual because otherwise the segue is called
// // before the indexPath is updated
// [self performSegueWithIdentifier:@"PlacePhotos" sender:self];
//}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"PlacePhotos"]) {
NSIndexPath* indexPath = [self.tableView indexPathForSelectedRow];
NSDictionary* selectedPlace = [self placeAtIndexPath:indexPath];
[segue.destinationViewController
setTitle:[self.selectedPlace objectForKey:FLICKR_PLACE_NAME]];
[segue.destinationViewController setPlace:self.selectedPlace];
setTitle:[selectedPlace objectForKey:FLICKR_PLACE_NAME]];
[segue.destinationViewController setPlace:selectedPlace];
}
else if ([segue.identifier isEqualToString:@"showMap"]) {
[segue.destinationViewController setAnnotations:[self mapAnnotations]];
Expand Down
35 changes: 16 additions & 19 deletions FlickrExplorer/en.lproj/MainStoryboard_iPhone.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
</subviews>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
</view>
<connections>
<segue destination="nxP-ei-n6N" kind="push" identifier="PlacePhotos" id="dA4-DO-fC9"/>
</connections>
</tableViewCell>
</prototypes>
<connections>
Expand All @@ -52,9 +55,6 @@
<refreshControl key="refreshControl" opaque="NO" multipleTouchEnabled="YES" contentMode="center" enabled="NO" contentHorizontalAlignment="center" contentVerticalAlignment="center" id="73w-Ih-IMN">
<autoresizingMask key="autoresizingMask"/>
</refreshControl>
<connections>
<segue destination="nxP-ei-n6N" kind="push" identifier="PlacePhotos" id="u9S-W3-Asd"/>
</connections>
</tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="nk5-NV-Oav" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
Expand Down Expand Up @@ -91,6 +91,9 @@
</subviews>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
</view>
<connections>
<segue destination="4Wd-Zq-qDW" kind="push" identifier="showPhoto" id="SWe-Z1-9ai"/>
</connections>
</tableViewCell>
</prototypes>
<connections>
Expand All @@ -110,9 +113,6 @@
<refreshControl key="refreshControl" opaque="NO" multipleTouchEnabled="YES" contentMode="center" enabled="NO" contentHorizontalAlignment="center" contentVerticalAlignment="center" id="4U5-Bs-gU2">
<autoresizingMask key="autoresizingMask"/>
</refreshControl>
<connections>
<segue destination="4Wd-Zq-qDW" kind="push" identifier="showPhoto" id="Icb-jJ-Eep"/>
</connections>
</tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="Yle-vZ-yqp" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
Expand Down Expand Up @@ -151,6 +151,9 @@
</subviews>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
</view>
<connections>
<segue destination="yNH-Gd-2iC" kind="push" identifier="showPhoto" id="fpX-iu-h8T"/>
</connections>
</tableViewCell>
</prototypes>
<connections>
Expand All @@ -168,9 +171,6 @@
<refreshControl key="refreshControl" opaque="NO" multipleTouchEnabled="YES" contentMode="center" enabled="NO" contentHorizontalAlignment="center" contentVerticalAlignment="center" id="0ZB-cn-TWA">
<autoresizingMask key="autoresizingMask"/>
</refreshControl>
<connections>
<segue destination="yNH-Gd-2iC" kind="push" identifier="showPhoto" id="bgE-dR-j5k"/>
</connections>
</tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="tsj-I8-RRa" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
Expand Down Expand Up @@ -212,7 +212,7 @@
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="SZf-wZ-8OZ" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="2113" y="-92"/>
<point key="canvasLocation" x="2173" y="-264"/>
</scene>
<!--Flickr Map View Controller-->
<scene sceneID="xHl-uG-B2W">
Expand Down Expand Up @@ -249,7 +249,7 @@
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="pcG-yr-Ct5" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="2113" y="-749"/>
<point key="canvasLocation" x="2173" y="-921"/>
</scene>
<!--Tab Bar Controller-->
<scene sceneID="NsU-wb-IB1">
Expand Down Expand Up @@ -598,7 +598,7 @@
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="jR2-K1-UP3" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="2639" y="1220"/>
<point key="canvasLocation" x="2505" y="896"/>
</scene>
<!--Flickr Map View Controller-->
<scene sceneID="wbt-io-EvN">
Expand Down Expand Up @@ -634,7 +634,7 @@
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="LOt-6y-Sty" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="2639" y="561"/>
<point key="canvasLocation" x="2505" y="237"/>
</scene>
<!--Navigation Controller-->
<scene sceneID="9yl-OV-Zm5">
Expand Down Expand Up @@ -674,9 +674,6 @@
</class>
<class className="FlickrTopPlacesTableViewController" superclassName="FlickrPlacesTableViewController">
<source key="sourceIdentifier" type="project" relativePath="./Classes/FlickrTopPlacesTableViewController.h"/>
<relationships>
<relationship kind="outlet" name="spinner" candidateClass="UIActivityIndicatorView"/>
</relationships>
</class>
<class className="ItineraryTableViewController" superclassName="UITableViewController">
<source key="sourceIdentifier" type="project" relativePath="./Classes/ItineraryTableViewController.h"/>
Expand Down Expand Up @@ -715,9 +712,9 @@
<simulatedScreenMetrics key="destination" type="retina4"/>
</simulatedMetricsContainer>
<inferredMetricsTieBreakers>
<segue reference="u9S-W3-Asd"/>
<segue reference="dXX-Hq-UfP"/>
<segue reference="Icb-jJ-Eep"/>
<segue reference="bgE-dR-j5k"/>
<segue reference="Xkn-pY-4wX"/>
<segue reference="SWe-Z1-9ai"/>
<segue reference="v2P-vH-cDu"/>
</inferredMetricsTieBreakers>
</document>

0 comments on commit a08e5dc

Please sign in to comment.