Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 03-11-2010, 10:29 AM   #1 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 20
Smile switching

my app has a uiwebview that loads a pdf, with a segmented control on the bottom,i have buttons on the other side of the segmented view that open different pdf files in the uiwebview. How do i make it so that when i click on the button it loads the pdf and automatically switches back to the other side of the segmented control.here is my code.

#import "YearbookViewController.h"


@implementation YearbookViewController


@synthesize webView, pdfUrl;
@synthesize switchView;
@synthesize pdfbutton;
@synthesize pdfbutton0;
@synthesize pdfbutton2;
@synthesize pdfbutton3;
@synthesize pdfbutton4;
@synthesize pdfbutton5;
@synthesize pdfbutton6;
@synthesize pdfbutton7;


- (void)viewDidLoad{


UIAlertView *prompt = [[UIAlertView alloc] initWithTitle:@"Password"
message:@"n/n/n/" // IMPORTANT
delegate:self
cancelButtonTitle:nil
otherButtonTitles:@"Enter", nil];


textField2 = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 45.0, 260.0, 25.0)];
[textField2 setBackgroundColor:[UIColor whiteColor]];
[textField2 setPlaceholder:@"password"];
[textField2 setSecureTextEntry:YES];
[prompt addSubview:textField2];

// set place
[prompt setTransform:CGAffineTransformMakeTranslation(0.0, 115.0)];
[prompt show];
[prompt release];


// set cursor and show keyboard


[super viewDidLoad];
webView.scalesPageToFit=YES;
webView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
NSString *pdfPath = [[NSBundle mainBundle] pathForResource:@"01 High School Students" ofType:@"pdf"];

/*
If we have to take from its operational directory, then the next 4 lines will be used...

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDire ctory, NSUserDomainMask, YES);
NSString *saveDirectory = [paths objectAtIndex:0];
NSString *saveFileName = @"myPDF.pdf";
NSString *pdfPath = [saveDirectory stringByAppendingPathComponent:saveFileName];
*/
self.pdfUrl = [NSURL fileURLWithPath:pdfPath];
[webView loadRequest:[NSURLRequest requestWithURL:pdfUrl]];
}


- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if ([textField2.text isEqualToString: @"falcon"]) {
}
else{
UIAlertView *prompt = [[UIAlertView alloc] initWithTitle:@"Password"
message:@"n/n/n/" // IMPORTANT
delegate:self
cancelButtonTitle:nil
otherButtonTitles:@"Enter", nil];


textField2 = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 45.0, 260.0, 25.0)];
[textField2 setBackgroundColor:[UIColor whiteColor]];
[textField2 setPlaceholder:@"password"];
[textField2 setSecureTextEntry:YES];
[prompt addSubview:textField2];

// set place
[prompt setTransform:CGAffineTransformMakeTranslation(0.0, 115.0)];
[prompt show];
[prompt release];


// set cursor and show keyboard
[textField2 becomeFirstResponder];
}
}

- (IBAction)toggleShowHide:(id)sender
{
UISegmentedControl *segmentedControl = (UISegmentedControl *)sender;
NSInteger segment = segmentedControl.selectedSegmentIndex;

if (segment == kShowSegmentIndex) [switchView setHidden:NO];
else [switchView setHidden:YES];
}
- (IBAction)pdfbutton:(id)sender
{
webView.scalesPageToFit=YES;
webView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
NSString *pdfPath = [[NSBundle mainBundle] pathForResource:@"02 Seniors" ofType:@"pdf"];
self.pdfUrl = [NSURL fileURLWithPath:pdfPath];
[webView loadRequest:[NSURLRequest requestWithURL:pdfUrl]];

}
- (IBAction)pdfbutton0:(id)sender
{
webView.scalesPageToFit=YES;
webView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
NSString *pdfPath = [[NSBundle mainBundle] pathForResource:@"03 Academics" ofType:@"pdf"];
self.pdfUrl = [NSURL fileURLWithPath:pdfPath];
[webView loadRequest:[NSURLRequest requestWithURL:pdfUrl]];
}
- (IBAction)pdfbutton2:(id)sender
{
webView.scalesPageToFit=YES;
webView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
NSString *pdfPath = [[NSBundle mainBundle] pathForResource:@"04 Activities" ofType:@"pdf"];
self.pdfUrl = [NSURL fileURLWithPath:pdfPath];
[webView loadRequest:[NSURLRequest requestWithURL:pdfUrl]];
}
- (IBAction)pdfbutton3:(id)sender
{
webView.scalesPageToFit=YES;
webView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
NSString *pdfPath = [[NSBundle mainBundle] pathForResource:@"05 Athletics" ofType:@"pdf"];
self.pdfUrl = [NSURL fileURLWithPath:pdfPath];
[webView loadRequest:[NSURLRequest requestWithURL:pdfUrl]];
}
- (IBAction)pdfbutton4:(id)sender
{
webView.scalesPageToFit=YES;
webView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
NSString *pdfPath = [[NSBundle mainBundle] pathForResource:@"06 Events" ofType:@"pdf"];
self.pdfUrl = [NSURL fileURLWithPath:pdfPath];
[webView loadRequest:[NSURLRequest requestWithURL:pdfUrl]];
}
- (IBAction)pdfbutton5:(id)sender
{
webView.scalesPageToFit=YES;
webView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
NSString *pdfPath = [[NSBundle mainBundle] pathForResource:@"07 Junior High" ofType:@"pdf"];
self.pdfUrl = [NSURL fileURLWithPath:pdfPath];
[webView loadRequest:[NSURLRequest requestWithURL:pdfUrl]];
}
- (IBAction)pdfbutton6:(id)sender
{
webView.scalesPageToFit=YES;
webView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
NSString *pdfPath = [[NSBundle mainBundle] pathForResource:@"08 Elementary Students" ofType:@"pdf"];
self.pdfUrl = [NSURL fileURLWithPath:pdfPath];
[webView loadRequest:[NSURLRequest requestWithURL:pdfUrl]];
}
- (IBAction)pdfbutton7:(id)sender
{
webView.scalesPageToFit=YES;
webView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
NSString *pdfPath = [[NSBundle mainBundle] pathForResource:@"01 High School Students" ofType:@"pdf"];
self.pdfUrl = [NSURL fileURLWithPath:pdfPath];
[webView loadRequest:[NSURLRequest requestWithURL:pdfUrl]];
}



- (void)dealloc
{
[webView release];
[pdfUrl release];
[super dealloc];
}
@end
evfalcon is offline   Reply With Quote
Old 03-11-2010, 11:08 AM   #2 (permalink)
iPhone SDK helper
 
Join Date: Feb 2010
Location: Austria, near Vienna
Posts: 169
Default

If I understood it correctly, you want to know how to switch the segmented Control programmatically? You can set it by doing the following:
Code:
segmentedControl.selectedSegmentIndex=0;
chaoz1337 is offline   Reply With Quote
Old 03-11-2010, 12:36 PM   #3 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 20
Default

Quote:
Originally Posted by chaoz1337 View Post
If I understood it correctly, you want to know how to switch the segmented Control programmatically? You can set it by doing the following:
Code:
segmentedControl.selectedSegmentIndex=0;
so what action could i use to switch from one side of the segmented control to the other, if i pressed a UIButton.

Last edited by evfalcon; 03-11-2010 at 01:14 PM.
evfalcon is offline   Reply With Quote
Old 03-12-2010, 02:19 AM   #4 (permalink)
iPhone SDK helper
 
Join Date: Feb 2010
Location: Austria, near Vienna
Posts: 169
Default

Quote:
Originally Posted by evfalcon View Post
so what action could i use to switch from one side of the segmented control to the other, if i pressed a UIButton.
just call the same action as the UISwitch does when you switch it manually!
chaoz1337 is offline   Reply With Quote
Old 03-12-2010, 10:03 AM   #5 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 20
Default

Quote:
Originally Posted by chaoz1337 View Post
just call the same action as the UISwitch does when you switch it manually!
thanks figured it out
evfalcon is offline   Reply With Quote
Reply

Bookmarks

Tags
ibaction, pdf, segmented control, uiview, uiwebview

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 285
21 members and 264 guests
2WeeksToGo, ADY, apatsufas, ckgni, dacapo, Dani77, Fritzer, ghost, HDshot, headkaze, jakerocheleau, joeallenpro, masc2279, mer10, mystic.purple, objch, Rudy, tathaastu, themathminister, timle8n1, Zool
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,878
Threads: 89,223
Posts: 380,731
Top Poster: BrianSlick (7,129)
Welcome to our newest member, olga2000
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 11:38 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0