02-06-2011, 02:05 AM
#1 (permalink )
Registered Member
Join Date: Jan 2011
Posts: 7
Button To Switch to a new XIB with a UIWebView
Hello! I am new to developing for the iPhone and I am currently working on a project that requires me to switch from a view containing three buttons to three separate uiwebviews. I have tried to create this, but when I do the app crashes when a button is clicked on.
02-08-2011, 02:53 PM
#2 (permalink )
Registered Member
Join Date: Feb 2009
Posts: 218
Code:
-(IBAction)socialButton:(id)sender {
NSString * twitter = @"http://m.twitter.com/";
NSString * facebook = @"http://www.facebook.com/";
NSString * youtube = @"http://www.youtube.com";
NSString * blog = @"http://blog.com";
NSString * storyLink = nil;
if (internetActive == YES) {
switch([sender tag])
{
case 0: // facebook
storyLink = facebook;
break;
case 1: // youtube
storyLink = youtube;
break;
case 2: // twitter
storyLink = twitter;
break;
case 3: // blog
storyLink = blog;
break;
}
NSURL *theURL = [NSURL URLWithString: storyLink];
NSURLRequest *request = [NSURLRequest requestWithURL: theURL];
webPage = [[[UIWebView alloc] initWithFrame:CGRectMake(1024,768,300,300)] autorelease];
webPage.scalesPageToFit = YES;
webPage.delegate = self;
[webPage loadRequest: request];
/*
CouponViewController *screen1 = [[CouponViewController alloc] initWithNibName:@"Coupon" bundle:nil];
screen1.delegate = self;
screen1.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
//[delegate didReceiveMessage:@"pressed web"];
[self presentModalViewController:screen1 animated:YES];
[screen1 release];
*/
newController = [[UIViewController alloc] init];
newController.view = webPage;
newController.title = @"Loading...";
UINavigationBar* theBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0.0f, 0.0f, [[UIScreen mainScreen] bounds].size.width, 48.0f)];
[theBar setDelegate:self];
UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithTitle:@"Close" style:UIBarButtonSystemItemDone target:self action:@selector(dismissModal)];
UINavigationItem *item = [[UINavigationItem alloc] initWithTitle:[socialArray objectAtIndex:[sender tag]]];
//theBar.autoresizingMask = UIViewAutoresizingFlexibleWidth;
item.leftBarButtonItem = leftButton;
item.hidesBackButton = YES;
[theBar pushNavigationItem:item animated:NO];
[leftButton release];
[item release];
theBar.tintColor = [UIColor blackColor];
[newController.view addSubview:theBar];
activityIndicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
activityIndicator.frame = CGRectMake(0.0, 0.0, 20.0, 20.0);
activityIndicator.center = self.view.center;
[newController.view addSubview: activityIndicator];
[self presentModalViewController:newController animated:YES ];
[UIApplication sharedApplication].statusBarHidden = YES;
} else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Status" message:@"Internet connection unavailable. \n\nPlease verify you are connected to a \nwireless or 3g network and try again"
delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];
[alert release];
}
}
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: 440
18 members and 422 guests
baja_yu , cgokey , dcool , Droverson , iAppDeveloper , ipodphone , karatebasker , laureix68 , LunarMoon , PapaSmurf , patapple , Paul Slocum , peterwilli , pipposanta , Rudy , SLIC , Sloshmonster , SuperDietGenius
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,696
Threads: 94,139
Posts: 402,961
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jasper_muc