Thanks for the response. However I'm unsure where I'm supposed to put that code. Here's what I have.
This is a split view iPad app which displays sequential pages of a pamphlet. So I have the root controller in its usual place on the left and the pages appear as an image in a UIImageView on the right.
RootView Controller.h
#import <UIKit/UIKit.h>
@class DetailViewController;
@interface RootViewController : UITableViewController {
DetailViewController *detailViewController;
//NSInteger pickedItem;
}
@property (nonatomic, retain) IBOutlet DetailViewController *detailViewController;
@property (nonatomic, assign) NSInteger pickedItem;
@end
RootViewController.m
- (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
/*
When a row is selected, set the detail view controller's detail item to
the item associated with the selected row.
*/
detailViewController.detailItem =
[NSString stringWithFormat:@"%@",
[listOfMovies objectAtIndex:indexPath.row]];
pickedItem = indexPath.row;
NSString *intString = [NSString stringWithFormat:@"%d", pickedItem];
detailViewController.label.text = intString;
}
Once the user selects an item in the table view on the left, I set an integer to tell which page was tapped.
This way, if the user alternatively swipes on the detailviewcontroller (instead of tapping from the table list), the detailviewcontroller will know which page it is currently showing (pickedItem) and will show the next in the sequence via a case statement.
DetailViewController.h
@interface DetailViewController : UIViewController <UIPopoverControllerDelegate, UISplitViewControllerDelegate> {
UIPopoverController *popoverController;
UIToolbar *toolbar;
UITabBar *tabBar;
id detailItem;
UILabel *detailDescriptionLabel;
RootViewController *rootViewController;
IBOutlet UIImageView *imageView;
BOOL transitioning;
BOOL barHidden;
}
@property (nonatomic, retain) IBOutlet UIToolbar *toolbar;
@property (nonatomic, retain) id detailItem;
@property (nonatomic, retain) IBOutlet UILabel *detailDescriptionLabel;
@property (nonatomic, retain) RootViewController *rootViewController;
@property (nonatomic, retain) IBOutlet UILabel *label;
@property (nonatomic, retain) IBOutlet UIView *detailViewController;
@property (nonatomic, retain) UIImageView *imageView;
@property (nonatomic, retain) IBOutlet UIToolbar *toolBar;
@property (nonatomic, retain) IBOutlet UITabBar *tabBar;
@end
DetailViewController.m
//...
@synthesize imageView, toolBar, tabBar, label, rootViewController;
//...
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch = [touches anyObject];
CGPoint currentPosition = [touch locationInView:self.view];
CGFloat deltaX = fabsf(gestureStartPoint.x - currentPosition.x);
CGFloat deltaY = fabsf(gestureStartPoint.y - currentPosition.y);
if(deltaX >= kMinimumGestureLength && deltaY <= kMaximumVariance){
label.text = @"Horizontal Swipe Detected";
switch (rootViewController.pickedItem) {
case 0:
imageView.image = [UIImage imageNamed:@"Page one.jpg"];
rootViewController.pickedItem = 1;
break;
case 1:
imageView.image = [UIImage imageNamed:@"Page two.jpg"];
rootViewController.pickedItem = 2;
break;
/...
}
}
else if(deltaY >= kMinimumGestureLength && deltaX <= kMaximumVariance){
label.text = @"Vertical Swipe Detected";
}
}
I have "horizontal swipe detected" statements so that I know it is in fact recording my swipes.
The behavior of the app is that it always treats "itemPicked" as 0, even though the Root View Controller accurately changes the value (I know this from a UILabel it updates).
So, of course, the problem is in the Detail View controller not getting the variable set by Root View Controller.
Thoughts? Thanks.