Note that there are some explanatory texts on larger screens.

plurals
  1. POiPhone Bookmark UIWebView - Displaying Page Title and Storing URL
    primarykey
    data
    text
    <p>I have a fully operational web browser application that stores bookmarked pages. When the bookmarks button is clicked, a listview of the stored websites is displayed. Instead of showing the URL, I would like the listview to display the title of the page, but I would like the UIWebView to go to the URL when the title is clicked.</p> <p>I have included the code below. I have also put the properties in both header files, but can't get it to work. Please help!</p> <p><strong>ExplorerViewController.h</strong></p> <pre><code>#import &lt;UIKit/UIKit.h&gt; @interface ExplorerViewController : UIViewController &lt;UITextFieldDelegate, UIWebViewDelegate, UIActionSheetDelegate&gt;{ UITextField *urlField; UIBarButtonItem *refreshButton; UIBarButtonItem *backButton; UIBarButtonItem *forwardButton; UIBarButtonItem *bookMarksButton; UIActivityIndicatorView *loadingActivity; UIWebView *webView; UINavigationBar *navigationBar; } @property (nonatomic, retain) IBOutlet UITextField *urlField; @property (nonatomic, retain) IBOutlet UIBarButtonItem *refreshButton; @property (nonatomic, retain) IBOutlet UIBarButtonItem *backButton; @property (nonatomic, retain) IBOutlet UIBarButtonItem *forwardButton; @property (nonatomic, retain) IBOutlet UIBarButtonItem *bookMarksButton; @property (nonatomic, retain) IBOutlet UIActivityIndicatorView *loadingActivity; @property (nonatomic, retain) IBOutlet UIWebView *webView; @property (nonatomic, retain) IBOutlet UINavigationBar *navigationBar; -(NSString*)repairURL:(NSString*)url; -(IBAction)refreshWebView; -(IBAction)goBack; -(IBAction)goForward; -(void)actualizeButtons; -(IBAction)bookmarksButtonTapped; -(IBAction)addBookmarkButtonTapped; @end </code></pre> <p><strong>ExplorerViewController.m</strong></p> <pre><code>-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { if (buttonIndex == 0) { NSMutableArray *bookmarks = [[[NSUserDefaults standardUserDefaults] arrayForKey:@"Bookmarks"] mutableCopy]; NSMutableArray *websitetitle = [[[NSUserDefaults standardUserDefaults] arrayForKey:@"Websitetitle"] mutableCopy]; if (!bookmarks) { bookmarks = [[NSMutableArray alloc] init]; } [bookmarks addObject:[[[[self webView]request] URL] absoluteString]]; [websitetitle addObject:[self.webView stringByEvaluatingJavaScriptFromString:@"document.title"]]; [[NSUserDefaults standardUserDefaults] setObject:bookmarks forKey:@"Bookmarks"]; [[NSUserDefaults standardUserDefaults] setObject:websitetitle forKey:@"Websitetitle"]; [bookmarks release]; [websitetitle release]; } } </code></pre> <p><strong>BookmarksViewController.h</strong></p> <pre><code>#import &lt;UIKit/UIKit.h&gt; @class ExplorerViewController; @interface BookmarksViewController : UIViewController &lt;UITableViewDelegate, UITableViewDataSource&gt;{ NSMutableArray *bookmarks; NSMutableArray *websitetitle; ExplorerViewController *explorerView; } @property (nonatomic, retain) NSMutableArray *bookmarks; @property (nonatomic, retain) NSMutableArray *websitetitle; @property (nonatomic, retain) ExplorerViewController *explorerView; -(IBAction)cancelButtonTapped; @end </code></pre> <p><strong>BookmarksViewController.m</strong></p> <pre><code>#import "BookmarksViewController.h" #import "ExplorerViewController.h" @implementation BookmarksViewController @synthesize bookmarks, websitetitle, explorerView; -(IBAction)cancelButtonTapped { [self.parentViewController dismissModalViewControllerAnimated:true]; } -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [bookmarks count]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *cellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:cellIdentifier] autorelease]; } cell.textLabel.text = [websitetitle objectAtIndex:indexPath.row]; return cell; } -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { explorerView.urlField.text = [bookmarks objectAtIndex:indexPath.row]; [explorerView textFieldShouldReturn:explorerView.urlField]; [self.parentViewController dismissModalViewControllerAnimated:true]; } -(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { if (editingStyle == UITableViewCellEditingStyleDelete) { [bookmarks removeObjectAtIndex:indexPath.row]; [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationFade]; [[NSUserDefaults standardUserDefaults] setObject:bookmarks forKey:@"Bookmarks"]; } } - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self; } - (void)dealloc { [super dealloc]; // e.g. self.myOutlet = nil; [explorerView release]; explorerView = nil; [bookmarks release]; bookmarks = nil; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload