I double checked the code against the book and the codes posted by other people on the forum but no matter what I did I always get the follow error code:
Request for member 'tag' in something not a structure or a union.
Please help.
H File:
Code:
//
// UsingViewsViewController.h
// UsingViews
//
// Created by Van Dai on 3/25/11.
// Copyright 2011 Dai Inc. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface UsingViewsViewController : UIViewController {
IBOutlet UIPageControl *pageControl;
IBOutlet UIImageView *imageView1;
IBOutlet UIImageView *imageView2;
UIImage *tempImageView, *bgImageView;
}
@property (nonatomic, retain) UIPageControl *pageControl;
@property (nonatomic, retain) UIImageView *imageView1;
@property (nonatomic, retain) UIImageView *imageView2;
@end
M File:
Code:
//
// UsingViewsViewController.m
// UsingViews
//
// Created by Van Dai on 3/25/11.
// Copyright 2011 Dai Inc. All rights reserved.
//
#import "UsingViewsViewController.h"
@implementation UsingViewsViewController
@synthesize pageControl;
@synthesize imageView1, imageView2;
/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
*/
/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
//---initialize the first imageview to display an image---
[imageView1 setImage:[UIImage imageNamed:@"Ferrari-Logo-Photo.jpg"]];
tempImageView = imageView2;
//---make the first imageview visible and hide the second---
[imageView1 setHidden:NO];
[imageView2 setHidden:YES];
//---add the event handler for the page control---
[pageControl addTarget:self
action:@selector(pageTurning:)
forControlEvents:UIControlEventValueChanged];
[super viewDidLoad];
}
//---when the page contorl's value is changed---
- (void) pageTurning: (UIPageControl *) pageController {
//---get the page number you can turn to---
NSInteger nextPage = [pageController currentPage];
switch (nextPage)
{
case 0:
[tempImageView setImage:
[UIImage imageNamed:@"Ferrari-Logo-Photo.jpg"]];
break;
case 1:
[tempImageView setImage:
[UIImage imageNamed:@"green_apple_logo.jpg"]];
break;
case 2:
[tempImageView setImage:
[UIImage imageNamed:@"windows-logo.jpg"]];
break;
case 3:
[tempImageView setImage:
[UIImage imageNamed:@"macbook pro.jpg"]];
break;
case 4:
[tempImageView setImage:
[UIImage imageNamed:@"hp_logo.jpg"]];
break;
default:
break;
}
//---switch the two imageview views---
if (tempImageView.tag == 0) {
tempImageView = imageView2;
bgImageView = imageView1;
}
else
{
tempImageView = imageView1;
bgImageView = imageView2;
}
//---animate the two views flipping---
[UIView beginAnimations:@"flipping view" context:nil];
[UIView setAnimationduration:0.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft
forView:tempImageView
cache:YES];
[tempImageView setHidden:YES];
[UIView commitAnimations];
[UIView beginAnimations:@"flippig view" context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationCurve::UIViewAnimationCurveEaseInOut];
[setAnimationTransition:UIViewAnimationTransitionFlipFromRight
forView:bgImageView
cache:YES];
[bgImageView setHidden:NO];
[UIView commitAnimations];
}
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[pageControl release];
[imageView1 release];
[imageView2 release];
[super dealloc];
}
- (void)alertView:(UIAlertView *)alertView
clickedButtonAtIndex:(NSInteger)buttonIndex {
NSLog(@"%d", buttonIndex);
}
- (void)actionSheet:(UIActionSheet *)actionSheet
clickedButtonAtIndex:(NSInteger)buttonIndex{
NSLog(@"%d", buttonIndex);
}
@end