03-11-2010, 10:29 AM
#1 (permalink )
Registered Member
Join Date: Jan 2010
Posts: 20
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
03-11-2010, 11:08 AM
#2 (permalink )
iPhone SDK helper
Join Date: Feb 2010
Location: Austria, near Vienna
Posts: 169
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;
03-11-2010, 12:36 PM
#3 (permalink )
Registered Member
Join Date: Jan 2010
Posts: 20
Quote:
Originally Posted by
chaoz1337
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 .
03-12-2010, 02:19 AM
#4 (permalink )
iPhone SDK helper
Join Date: Feb 2010
Location: Austria, near Vienna
Posts: 169
Quote:
Originally Posted by
evfalcon
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!
03-12-2010, 10:03 AM
#5 (permalink )
Registered Member
Join Date: Jan 2010
Posts: 20
Quote:
Originally Posted by
chaoz1337
just call the same action as the UISwitch does when you switch it manually!
thanks figured it out
Thread Tools
Display Modes
Linear Mode
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
» 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