.h==================================================================
#import <UIKit/UIKit.h>
@interface t5ViewController : UIViewController <UIAlertViewDelegate, UIActionSheetDelegate>{
IBOutlet UIImageView *imageView;
IBOutlet UIPageControl *pageControl;
IBOutlet UIWebView *webView;
}
@property (nonatomic, retain) UIWebView *webView;
@property (nonatomic, retain) UIImageView *imageView;
@property (nonatomic, retain) UIPageControl *pageControl;
@end
.m===================================================================
#import "t5ViewController.h"
@implementation t5ViewController
@synthesize imageView;
@synthesize pageControl;
@synthesize webView;
- (void)dealloc
{
[super dealloc];
}
- (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.
}
#pragma mark - View lifecycle
-(void) pageTurning : (UIPageControl *) pageController{
NSLog(@"current page : %d", [pageController currentPage]);
switch([pageController currentPage]){
case 0:
[imageView setImage:[UIImage imageNamed:@"s1.png"]]; break;
case 1:
[imageView setImage:[UIImage imageNamed:@"s2.jpg"]]; break;
default:
[imageView setImage:[UIImage imageNamed:@"s3.jpg"]]; break;
}
}
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
[super viewDidLoad];
UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"TTTitle" delegate:self cancelButtonTitle:@"cancel" destructiveButtonTitle:@"xxx" otherButtonTitles:@"HHHHHHH", nil];
[sheet showInView:self.view];
[sheet release];
UIAlertView *v = [[UIAlertView alloc]
initWithTitle:@"Hi" message:@"welcome to china" delegate:self cancelButtonTitle:@"quit" otherButtonTitles:@"xxx", nil];
[v show];
[v release];
[imageView setImage:[UIImage imageNamed:@"s1.png"]];
[imageView setHighlighted:false];
[pageControl addTarget:self action:@selector(pageTurning:) forControlEvents:UIControlEventValueChanged];
NSURL *url = [NSURL URLWithString:@"http://www.baidu.com"];
NSURLRequest *req = [NSURLRequest requestWithURL:url];
[webView loadRequest:req];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
NSLog(@"hello, %d", buttonIndex);
if(buttonIndex == 1){
NSLog(@"press xxx");
}else if(buttonIndex == 0)
NSLog(@"pressed qqqqqqqquit");
}
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
NSLog(@"pppppppppppppressed actionsheet, %d", buttonIndex);
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end