How many lines of code do you have to write for displaying a webpage ‘in-app”.
3 methinks.

Wouldn’t be great if there is a built in class for presenting a webpage using “presentModalViewController”? Meet MKWebViewController.

Step 1:

Drop the attached three files into your project and write the following three lines on your action callback (buttonDidTap) or equivalent methods

MKWebViewController *controller = [[[MKWebViewController alloc] initWithNibName:@"MKWebViewController" bundle:nil] autorelease];
controller.url = @"";
[self presentModalViewController:controller animated:YES];

Step 2:

Nah, no step 2.

That’s it. On landscape mode, the controller even rotates and hides the toolbar. On portrait mode it brings back the toolbar and provides you a close button. The controller automatically handles any errors, and displays appropriate error messages, close the window when the user taps on the “Dismiss” button on the error message. What more, the controller can also display any iOS supported file format that includes, PDF, Office, iWork documents.

Give it a try, and do let me know your feedback.

Source Code


Follow me on Twitter