Good morning,
I'm trying to create a new interface for implementing a Page View Controller but I'm doing something wrong because it's not working. I hope someone can see the error and help me with that because I'm a little bit stuck on this problem.
http://autograpp.com/Main.jpg
aupViewController.m
#import "aupViewController.h"
#import <FacebookSDK/FacebookSDK.h>
#import "SBJson.h"
#interface TutorialViewController ()
#end
#implementation TutorialViewController
- (void)viewDidLoad
{
// Create the data model
_pageTitles = #[#"Over 200 Tips and Tricks", #"Discover Hidden Features", #"Bookmark Favorite Tip", #"Free Regular Update"];
_pageImages = #[#"page1.png", #"page2.png", #"page3.png", #"page4.png"];
// Create page view controller
self.pageViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"PageViewController"];
self.pageViewController.dataSource = self;
PageContentViewController *startingViewController = [self viewControllerAtIndex:0];
NSArray *viewControllers = #[startingViewController];
[self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
// Change the size of page view controller
self.pageViewController.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 30);
[self addChildViewController:_pageViewController];
[self.view addSubview:_pageViewController.view];
[self.pageViewController didMoveToParentViewController:self];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)startWalkthrough:(id)sender {
PageContentViewController *startingViewController = [self viewControllerAtIndex:0];
NSArray *viewControllers = #[startingViewController];
[self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionReverse animated:NO completion:nil];
}
- (PageContentViewController *)viewControllerAtIndex:(NSUInteger)index
{
if (([self.pageTitles count] == 0) || (index >= [self.pageTitles count])) {
return nil;
}
// Create a new view controller and pass suitable data.
PageContentViewController *pageContentViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"PageContentViewController"];
pageContentViewController.imageFile = self.pageImages[index];
pageContentViewController.titleText = self.pageTitles[index];
pageContentViewController.pageIndex = index;
return pageContentViewController;
}
#pragma mark - Page View Controller Data Source
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController
{
NSUInteger index = ((PageContentViewController*) viewController).pageIndex;
if ((index == 0) || (index == NSNotFound)) {
return nil;
}
index--;
return [self viewControllerAtIndex:index];
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController
{
NSUInteger index = ((PageContentViewController*) viewController).pageIndex;
if (index == NSNotFound) {
return nil;
}
index++;
if (index == [self.pageTitles count]) {
return nil;
}
return [self viewControllerAtIndex:index];
}
- (NSInteger)presentationCountForPageViewController:(UIPageViewController *)pageViewController
{
return [self.pageTitles count];
}
- (NSInteger)presentationIndexForPageViewController:(UIPageViewController *)pageViewController
{
return 0;
}
#end
aupViewController.h
#import <UIKit/UIKit.h>
#import <FacebookSDK/FacebookSDK.h>
#import "PageContentViewController.h"
#interface TutorialViewController : UIViewController <UIPageViewControllerDataSource>
- (IBAction)startWalkthrough:(id)sender;
#property (strong, nonatomic) UIPageViewController *pageViewController;
#property (strong, nonatomic) NSArray *pageTitles;
#property (strong, nonatomic) NSArray *pageImages;
#end
#interface aupViewController : UIViewController <FBLoginViewDelegate>
#property (weak, nonatomic) IBOutlet FBLoginView *loginButton;
#property (weak, nonatomic) IBOutlet UITextField *txtUsername;
#property (weak, nonatomic) IBOutlet UITextField *txtPassword;
- (IBAction)loginClicked:(id)sender;
- (IBAction)backgroundClick:(id)sender;
- (IBAction)textFieldReturn:(id)sender;
#end
#interface LoginViewController : UIViewController
#property (weak, nonatomic) IBOutlet UITextField *txtUsername;
#property (weak, nonatomic) IBOutlet UITextField *txtPassword;
#property (weak, nonatomic) IBOutlet UITextField *txtMail;
- (IBAction)registerClicked:(id)sender;
- (IBAction)backgroundClick:(id)sender;
- (IBAction)textFieldReturn:(id)sender;
#end
#interface MainViewController : UIViewController
#end
PageContentViewController.h
#import <UIKit/UIKit.h>
#interface PageContentViewController : UIViewController
#property (weak, nonatomic) IBOutlet UIImageView *backgroundImageView;
#property (weak, nonatomic) IBOutlet UILabel *titleLabel;
#property NSUInteger pageIndex;
#property NSString *titleText;
#property NSString *imageFile;
#end
PageContentViewController.m
#import "PageContentViewController.h"
#interface PageContentViewController ()
#end
#implementation PageContentViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.backgroundImageView.image = [UIImage imageNamed:self.imageFile];
self.titleLabel.text = self.titleText;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
But I'm getting the error:
Cannot find interface declaration for TutorialViewController, did you mean LoginViewController?
And why is this not working? I really appreciate your help.
Thanks in advance.
The problem is that I had the wrong path in one of my files. I correct it and now everything is working. Thanks for your help.
Related
I am making simple intro screen. the screen slides on swipe but I want also swipe the intro screens with button tap but when I tap next button it shows an error.
complete code
#import <UIKit/UIKit.h>
#import "WalkthroughPageViewController.h"
#interface WalkthroughContentViewController : UIViewController
#property (weak, nonatomic) IBOutlet UILabel *pageLbl;
#property (weak, nonatomic) IBOutlet UIButton *nextBtn;
#property(strong,nonatomic)WalkthroughPageViewController *pageVC;
#property NSUInteger index;
#property NSString *heading;
#end
WalkthroughContentViewController.m
#import "WalkthroughContentViewController.h"
#interface WalkthroughContentViewController ()
#end
#implementation WalkthroughContentViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.pageLbl.text = self.heading;
switch (self.index) {
case 0:
case 1:
[self.nextBtn setTitle:#"Next" forState:UIControlStateNormal];
break;
case 2:
[self.nextBtn setTitle:#"Done" forState:UIControlStateNormal];
break;
default:
break;
}
}
- (IBAction)nextBtn:(id)sender {
switch (self.index) {
case 0:
case 1:
self.pageVC = ((WalkthroughPageViewController*)self.parentViewController);
[self.pageVC forward:self.index];
break;
case 2:
[self performSegueWithIdentifier:#"LoginScreen" sender:nil];
break;
default:
break;
}
}
#end
WalkthroughPageViewController.h
#import <UIKit/UIKit.h>
#interface WalkthroughPageViewController :UIPageViewController<UIPageViewControllerDataSource>
#property (strong, nonatomic) UIPageViewController *pageViewController;
#property NSArray *pageHeading;
-(void)forward:(NSUInteger)index;
#end
WalkthroughPageViewController.m
#import "WalkthroughPageViewController.h"
#import "WalkthroughContentViewController.h"
#interface WalkthroughPageViewController ()
#end
#implementation WalkthroughPageViewController
NSUInteger indexP;
- (void)viewDidLoad {
[super viewDidLoad];
self.pageHeading = #[#"page1",#"page2",#"page3"];
self.pageViewController = [[UIPageViewController alloc] init];
self.pageViewController.dataSource = self;
WalkthroughContentViewController *startingViewController = [self viewControllerAtIndex:0];
NSArray *viewControllers = #[startingViewController];
[_pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
[self addChildViewController:self.pageViewController];
[self.view addSubview:self.pageViewController.view];
[self.pageViewController didMoveToParentViewController:self];
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController
{
indexP = ((WalkthroughContentViewController*) viewController).index;
if ((indexP == 0) || (indexP == NSNotFound)) {
return nil;
}
indexP--;
return [self viewControllerAtIndex:indexP];
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController
{
indexP = ((WalkthroughContentViewController*) viewController).index;
if (indexP == NSNotFound) {
return nil;
}
indexP++;
if (indexP == [self.pageHeading count]) {
return nil;
}
return [self viewControllerAtIndex:indexP];
}
- (WalkthroughContentViewController *)viewControllerAtIndex:(NSUInteger)index
{
if ((index == NSNotFound) || (index >= [self.pageHeading count])) {
return nil;
}
// Create a new view controller and pass suitable data.
WalkthroughContentViewController *pageContentViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"WalkthroughContentViewController"];
pageContentViewController.heading = self.pageHeading[index];
pageContentViewController.index = index;
return pageContentViewController;
}
- (NSInteger)presentationCountForPageViewController:(UIPageViewController *)pageViewController
{
return [self.pageHeading count];
}
- (NSInteger)presentationIndexForPageViewController:(UIPageViewController *)pageViewController
{
return 0;
}
-(void)forward:(NSUInteger)index{
[self.pageViewController setViewControllers:#[[self viewControllerAtIndex:index]] direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:nil];
}
#end
**Error:: **
[UIPageViewController forward:]: unrecognized selector sent to instance
I want to put some static content (buttons, views etc) on UIPageViewController. But I don't know how.
Any ideas?
Just create a container uiviewcontroller that will have e.g. a static button and an empty uiview. Create them as iboutlets and a usual property UIPageViewController called pvc. Then you can create a pvc in code and add it to the uiview outlet via addSubview:.
This is some code copied from a project i did last weeek. There are Skidata in a UIPageViewController and put an UIImage of a snowflake as overlay about it. I copied only the relevant parts of code. Hope this will help you:
SkiViewController.m
#interface SkiViewController () <UIPageViewControllerDataSource>
#property (strong, nonatomic) UIPageViewController *pageController;
#property (strong, nonatomic) SkiDataArray* skiDataArray;
#property (weak, nonatomic) IBOutlet UIImageView *imageView;
#property (weak, nonatomic) IBOutlet UIView *pageDataView;
#end
#implementation SkiViewController
- (SkiSubViewController *)viewControllerAtIndex:(NSUInteger)index
{
SkiSubViewController *childViewController = [[SkiSubViewController alloc] initWithNibName:#"SkiSubViewController" bundle:nil];
childViewController.indexNumber = index;
if(self.skiDataArray)
{
childViewController.skiData = self.skiDataArray[index];
}
return childViewController;
}
#pragma mark - lify cycle
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.pageController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];
self.pageController.dataSource = self;
[self addPageControllerViewControllers];
[self addPageControllerView];
[self addChildViewController:self.pageController];
[self.pageController didMoveToParentViewController:self];
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self updateData]; // download ski data and stuff
}
- (void)addPageControllerViewControllers
{
SkiSubViewController *viewController = [self viewControllerAtIndex:0];
if(self.skiDataArray)
{
viewController.skiData = self.skiDataArray[0];
}
[self.pageController setViewControllers:#[viewController] direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
}
- (void)addPageControllerView
{
self.pageController.view.translatesAutoresizingMaskIntoConstraints = NO; // avoids conflicts with auto generated constraints
[self.pageDataView addSubview:self.pageController.view];
NSDictionary *views = #{ #"subview": self.pageController.view };
[self.pageDataView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:#"H:|[subview]|" options:0 metrics: 0 views:views]];
[self.pageDataView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:#"V:|[subview]|" options:0 metrics: 0 views:views]];
[self.pageDataView updateConstraintsIfNeeded];
}
#pragma mark - uipageviewcontroller data source
- (UIViewController*)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController
{
NSUInteger index = [(SkiSubViewController *)viewController indexNumber];
if (index == 0)
{
return nil;
}
else
{
index--;
return [self viewControllerAtIndex:index];
}
}
- (UIViewController*)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController
{
NSUInteger index = ((SkiSubViewController *)viewController).indexNumber;
index++;
if (index == self.skiDataArray.count)
{
return nil;
}
else
{
return [self viewControllerAtIndex:index];
}
}
- (NSInteger)presentationCountForPageViewController:(UIPageViewController *)pageViewController
{
return self.skiDataArray.count;
}
- (NSInteger)presentationIndexForPageViewController:(UIPageViewController *)pageViewController
{
return 0;
}
#end
SkiSubViewController.h
#interface SkiSubViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>
#property (assign, nonatomic) NSInteger indexNumber;
#property (strong, nonatomic) SkiData* skiData;
#end
SkiSubViewController.m
#interface SkiSubViewController ()
#property (weak, nonatomic) IBOutlet UILabel *label;
#end
#implementation SkiSubViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.label.text = [NSString stringWithFormat:#"Number %li", (long)self.indexNumber];
}
#end
Basically, I am making a page app, which use UIPageViewController. When the user scrolls the page, they can see different content. The problem now is, when I scroll the page, the first and second page works properly, and the index is correct. But when I scroll to the third page, the index keeps at "1", and don't change afterwards. And the other page keeps the appearance of the second page, whose index is "1".
I was following the tutorial: http://www.appcoda.com/uipageviewcontroller-storyboard-tutorial/
My code:
View Controller.h
#import <UIKit/UIKit.h>
#import "PageContentViewController.h"
#import "PageViewController.h"
#interface ViewController : UIViewController<UIPageViewControllerDataSource, UIPageViewControllerDelegate>
#property (strong, nonatomic) PageViewController *pageViewController;
#property (strong, nonatomic) NSArray *pageTitles;
#end
View Controller.m:
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.pageTitles = #[#"First Page", #"Second Page", #"Third Page"];
self.pageViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"PageViewController"];
self.pageViewController.dataSource = self;
if ([self.pageTitles count])
{
PageContentViewController *startingViewController = [self viewControllerAtIndex: 0];
NSArray *viewControllers = #[startingViewController];
[self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
self.pageViewController.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
[self addChildViewController:self.pageViewController];
[self.view addSubview:self.pageViewController.view];
[self.pageViewController didMoveToParentViewController:self];
}
}
- (PageContentViewController *) viewControllerAtIndex: (NSUInteger)index{
if (index < [self.pageTitles count])
{
PageContentViewController *pageContentViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"PageContentViewController"];
pageContentViewController.titleText = self.pageTitles[index];
NSLog(#"%li", index);
UIColor *backgroundColor;
switch (index) {
case 0:
backgroundColor = [UIColor greenColor];
break;
case 1:
backgroundColor = [UIColor blueColor];
break;
case 2:
backgroundColor = [UIColor purpleColor];
break;
default:
break;
}
pageContentViewController.backgroundColor = backgroundColor;
return pageContentViewController;
}
return nil;
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController
{
NSUInteger index = ((PageContentViewController *)viewController).pageIndex;
if (index == NSNotFound)
{
return nil;
}
index++;
if (index == [self.pageTitles count])
{
return nil;
}
return [self viewControllerAtIndex:index];
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController
{
NSUInteger index = ((PageContentViewController *)viewController).pageIndex;
if (index == 0 || index == NSNotFound)
{
return nil;
}
index--;
return [self viewControllerAtIndex:index];
}
- (NSInteger) presentationCountForPageViewController:(UIPageViewController *)pageViewController
{
return [self.pageTitles count];
}
- (NSInteger) presentationIndexForPageViewController:(UIPageViewController *)pageViewController
{
return 0;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
Page Content View Controller.h
#import <UIKit/UIKit.h>
#interface PageContentViewController : UIViewController
#property (weak, nonatomic) IBOutlet UIView *backgroundView;
#property (weak, nonatomic) IBOutlet UILabel *titleLable;
#property (nonatomic) NSUInteger pageIndex;
#property (strong, nonatomic) NSString *titleText;
#property (strong, nonatomic) UIColor *backgroundColor;
#end
Page Content View Controller.m
#import "PageContentViewController.h"
#interface PageContentViewController ()
#end
#implementation PageContentViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.titleLable.text = self.titleText;
[self.backgroundView setBackgroundColor:self.backgroundColor];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
#end
In viewControllerAtIndex:, you need to set the value of pageIndex property of the pageContentViewController:
pageContentViewController.pageIndex = index;
I'm trying to implement an iCarousel that will pass information on to two other view controllers when an image is chosen. While the iCarousel loads perfectly and transitions to the next VC, the information is not displayed on the new VC.
The approach I chose was to create an NSObject file. I can't simply pass the info from VC to VC since I have several VC's that need the information and I'd prefer not to create a singleton or use AppDelegate if possible.
FYI: I do have a tap gesture recognizer added on top of the UIView that acts as the segue to the next VC if that makes any difference.
I've tried every possible tutorial out there and can't seem to figure out my problem. I just need to display a text label and a picture, which should really be pretty easy. Can someone take a quick glance at my code to see what I'm doing wrong?
My NSObject File:
#import <Foundation/Foundation.h>
#interface Stop : NSObject
#property (nonatomic, strong) NSString *title;
#property (nonatomic, strong) NSString *image;
#end
First ViewController.h (with iCarousel on it):
#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
#import "iCarousel.h"
#import "DirectionsViewController.h"
#import "Stop.h"
#interface StopsMenuViewController : UIViewController <iCarouselDataSource, iCarouselDelegate>
#property (strong, nonatomic) IBOutlet iCarousel *carousel;
#property (strong, nonatomic) IBOutlet UILabel *titleLabel;
//Title
#property (nonatomic, strong) NSArray *stopTitles;
#property (nonatomic, strong) NSString *stopChosen;
//Image
#property (nonatomic, strong) NSArray *stopImages;
#property (nonatomic, strong) NSString *imageChosen;
#end
First ViewController.m:
#import "StopsMenuViewController.h"
#interface StopsMenuViewController () {
NSMutableArray *allInfo; }
#end
#implementation StopsMenuViewController
#synthesize titleLabel, carousel, stopImages, stopTitles, stopChosen, imageChosen;
- (void)awakeFromNib {
NSString *myPlist = [[NSBundle mainBundle] pathForResource:#"Chinatown" ofType:#"plist"];
NSDictionary *rootDictionary = [[NSDictionary alloc] initWithContentsOfFile:myPlist];
self.stopImages = [rootDictionary objectForKey:#"StopImages"];
self.stopTitles = [rootDictionary objectForKey:#"StopTitles"];
}
- (void)carouselDidScroll:(iCarousel *)carousel {
[titleLabel setText:[NSString stringWithFormat:#"%#", [self.stopTitles
objectAtIndex:self.carousel.currentItemIndex]]];
}
- (void)dealloc {
self.carousel.delegate = nil;
self.carousel.dataSource = nil;
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:#"toDirections"])
{
DirectionsViewController *dvc = [segue destinationViewController];
int itemId = [self.carousel currentItemIndex];
NSIndexPath *path = [NSIndexPath indexPathForRow:itemId inSection:0];
Stop *current = [allInfo objectAtIndex:path.row];
[dvc setPassInfo:current];
}
}
- (void)viewDidLoad {
[super viewDidLoad];
self.carousel.type = iCarouselTypeCoverFlow2;
allInfo = [[NSMutableArray alloc] init];
Stop *info = [[Stop alloc] init];
stopChosen = [NSString stringWithFormat:#"%#", [self.stopTitles objectAtIndex:self.carousel.currentItemIndex]];
[info setTitle:stopChosen];
[allInfo addObject:info];
info = [[Stop alloc] init];
self.imageChosen = [NSString stringWithFormat:#"%#", [self.stopImages
objectAtIndex:self.carousel.currentItemIndex]];
[info setTitle:self.imageChosen];
[allInfo addObject:info];
}
- (void)viewDidUnload
{
[super viewDidUnload];
self.carousel = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
- (NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel {
return [self.stopImages count];
}
- (NSUInteger)numberOfVisibleItemsInCarousel:(iCarousel *)carousel {
return 4;
}
- (UIView *)carousel:(iCarousel *)_carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view {
if (view == nil)
{
view = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[self.stopImages objectAtIndex:index]]];
}
return view;
}
- (void)carousel:(iCarousel *)carousel didSelectItemAtIndex:(NSInteger)index {
DirectionsViewController *dvc = [self.storyboard instantiateViewControllerWithIdentifier:#"dvc"];
[self.navigationController pushViewController:dvc animated:YES];
}
#end
Second ViewController.h:
#import <UIKit/UIKit.h>
#import "Stop.h"
#interface DirectionsViewController : UIViewController
#property (strong, nonatomic) IBOutlet UILabel *titleLabel;
#property (strong, nonatomic) IBOutlet UIImageView *imageBox;
#property (nonatomic, strong) Stop *PassInfo;
#property (nonatomic, strong) NSString *stopTitle;
#property (nonatomic, strong) NSString *myStopTitle;
#end
Second ViewController.m:
#import "DirectionsViewController.h"
#interface DirectionsViewController ()
#end
#implementation DirectionsViewController
#synthesize PassInfo;
- (void)viewDidLoad {
[super viewDidLoad];
[self.titleLabel setText:[PassInfo title]];
UIImage *image = [UIImage imageNamed:[PassInfo image]];
[self.imageBox setImage:image];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
#end
Instead of
- (void)carousel:(iCarousel *)carousel didSelectItemAtIndex:(NSInteger)index {
DirectionsViewController *dvc = [self.storyboard instantiateViewControllerWithIdentifier:#"dvc"];
[self.navigationController pushViewController:dvc animated:YES];
}
Use
- (void)carousel:(iCarousel *)carousel didSelectItemAtIndex:(NSInteger)index {
[self performSegueWithIdentifier:#"toDirections" sender:self];
}
In your code, you're instantiating the second view controller and presenting it, which is not the same as performing a segue. Therefore the method - prepareForSegue:sender: will not be invoked.
I'm building an app based on a main view controller (CalViewController) to do some math and then, there are two view Controllers (DrinksViewController & FoodViewController).
I build CalViewController and DrinksViewController but when I want to duplicate DrinksViewController to build FoodViewController (same view with different data) a bug appeared : "Property 'bouffon' not found on object of type FoodViewController".
Whereas 'bouffon' defined in my foodViewController.h then imported by CalViewController. It works with 'CaloriesDepensees' (data from DrinksViewController) but not with 'bouffon'. I check every line from DrinksViewController.h and .m and it appears it is exactly the same as FoodViewController.h and .m (with different data obviously).
Custom Class & Storyboard ID is FoodViewController also for this View Controller (in Storyboard, identity inspector).
Big Thanks for your help !
Pierre
Here CalViewController.h :
#import <UIKit/UIKit.h>
#import "CalAppDelegate.h"
#import "DrinksViewController.h"
#import "FoodViewController.h"
#interface CalViewController : UIViewController
{
double temps;
double distance;
double vitesse;
double poids;
NSString *caloriesText;
}
#property (weak, nonatomic) IBOutlet UITextField *saisieTemps;
#property (weak, nonatomic) IBOutlet UITextField *saisieDistance;
#property (weak, nonatomic) IBOutlet UITextField *saisiePoids;
#property (weak, nonatomic) IBOutlet UITextView *resultat;
#property (weak, nonatomic) IBOutlet UISwitch *saisieDefaut;
#property (weak, nonatomic) IBOutlet UILabel *poidsDefaut;
- (IBAction)tempsAction:(id)sender;
- (IBAction)distanceAction:(id)sender;
- (IBAction)defautAction:(id)sender;
- (IBAction)saisieReturn :(id)sender;
- (IBAction)calcul:(id)sender;
- (IBAction)paramSwitch:(id)sender;
- (IBAction)poidsAction:(id)sender;
#end
Here CalViewController.m :
#interface CalViewController ()
#end
#implementation CalViewController
#synthesize resultat;
#synthesize saisieDistance;
#synthesize saisieTemps;
#synthesize saisiePoids;
#synthesize saisieDefaut;
#synthesize poidsDefaut;
double calories;
double factCal;
double vitesse;
double poidsDonne=75;
- (void)viewDidLoad
{
[super viewDidLoad];
calories=1.0;
if (saisieDefaut.on) {
saisiePoids.hidden=YES;
poidsDefaut.hidden=NO;
}
else {
saisiePoids.hidden=NO;
poidsDefaut.hidden=YES;
}
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)tempsAction:(id)sender {
temps = [[saisieTemps text] doubleValue];
}
- (IBAction)distanceAction:(id)sender {
distance = [[saisieDistance text] doubleValue];
}
- (IBAction)poidsAction:(id)sender {
poids = [[saisiePoids text] doubleValue];
}
- (IBAction)defautAction:(id)sender {
}
- (IBAction)saisieReturn :(id)sender{
[sender resignFirstResponder];
}
- (IBAction)calcul:(id)sender {
temps = [[saisieTemps text] doubleValue];
distance = [[saisieDistance text] doubleValue];
vitesse = distance*1000/temps;
if (vitesse <110)
factCal=1.06;
else if (vitesse < 120)
factCal=1.052;
else if (vitesse < 130)
factCal=1.046;
else if (vitesse < 140)
factCal=1.041;
else if (vitesse < 150)
factCal=1.037;
else if (vitesse < 160)
factCal=1.034;
else if (vitesse < 280)
factCal=1.030;
else if (vitesse < 300)
factCal=1.035;
else if (vitesse < 320)
factCal=1.039;
else if (vitesse < 330)
factCal=1.043;
else if (vitesse < 340)
factCal=1.046;
else if (vitesse < 350)
factCal=1.049;
else if (vitesse < 360)
factCal=1.052;
else if (vitesse < 370)
factCal=1.055;
else if (vitesse < 380)
factCal=1.058;
else if (vitesse < 390)
factCal=1.049;
else if (vitesse>=390)
factCal=1.065;
if (saisieDefaut.on)
calories= factCal*distance*poidsDonne;
else
calories= factCal*distance*poids;
resultat.text = [NSString stringWithFormat:#"%0.f", calories];
}
- (IBAction)paramSwitch:(id)sender {
if (saisieDefaut.on) {
saisiePoids.hidden=YES;
poidsDefaut.hidden=NO;
}
else {
saisiePoids.hidden=NO;
poidsDefaut.hidden=YES;
}
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([segue.identifier isEqualToString:#"showFoodSegue"]){
FoodViewController *controller = (FoodViewController *)segue.destinationViewController;
controller.bouffon = calories;
The error appears here, 'bouffon' is not known as an object of FoodViewController.
}
if([segue.identifier isEqualToString:#"showDrinksSegue"]){
DrinksViewController *controllera = (DrinksViewController *)segue.destinationViewController;
controllera.caloriesDepensees = calories;
}
}
#end
Here FoodViewController.h :
#import <UIKit/UIKit.h>
#import "CalAppDelegate.h"
#interface FoodViewController : UIViewController <UICollectionViewDataSource, UICollectionViewDelegate>
#property (weak, nonatomic) IBOutlet UICollectionView *foodCollectionView;
#property(nonatomic) double bouffon;
#end
Here FoodViewController.m :
#import "FoodViewController.h"
#import "FoodCell.h"
#interface FoodViewController ()
{
NSArray *arrayOfImages;
NSArray *arrayOfDescriptions;
NSArray *arrayOfCalories;
double caloriesFoodDouble;
NSString *caloriesFoodObject;
double receptionDouble;
}
#end
#implementation FoodViewController
#synthesize bouffon;
#synthesize foodCollectionView;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
//Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[[self foodCollectionView]setDataSource:self];
[[self foodCollectionView]setDelegate:self];
arrayOfImages = [[NSArray alloc]initWithObjects:#"beer2.jpg",#"biere1.png",nil];
arrayOfDescriptions =[[NSArray alloc]initWithObjects:#"bouffe",#"binouffe",nil];
arrayOfCalories =[[NSArray alloc]initWithObjects:#"1000",#"10000",nil];
}
- (NSInteger) collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{ return [arrayOfDescriptions count];
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier1=#"Cell1";
FoodCell *cell1 = ([collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier1 forIndexPath:indexPath]);
[[cell1 foodImage]setImage:[UIImage imageNamed:[arrayOfImages objectAtIndex:indexPath.item]]];
caloriesFoodObject=[arrayOfCalories objectAtIndex:indexPath.item];
caloriesFoodDouble = [caloriesFoodObject doubleValue];
caloriesFoodDouble=caloriesFoodDouble/bouffon;
[[cell1 foodLabel]setText:[NSString stringWithFormat:#"%.1f%#", caloriesFoodDouble,[arrayOfDescriptions objectAtIndex:indexPath.item]]];
return cell1;
}
- (NSInteger)numberOfSections:(UICollectionView *) collectionView
{return 1;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
After some intense hours of research, I figure out that another FoodViewController.m was created and present in my Finder.
So, just have to check my Finder and delete the wrong file.