Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I am not quite sure if I understood what you mean. My initial understanding was similar to @sergio - how to implement a gesture recognizer. But it seems you are looking for "how to design" your MVC (based on your comment to @sergio : "<em>...My issue is actually getting the array and everything passed over...</em>".</p> <p>If so, here is a suggestion that might be helpful:</p> <p>If you refactor your model, all entries, into its own class (subclass of <code>NSObject</code>) and declare some convenient properties, so that when, let's say, <code>EntriesViewController</code> pushes <code>WebViewController</code> into the navigation stack, instead of passing the entry itself, you can pass a pointer to the model. <code>WebViewController</code> can make its own inquiries to model.</p> <p>Something like this diagram:</p> <p><img src="https://i.stack.imgur.com/boYVu.png" alt="enter image description here"></p> <p>Hope this helps!</p> <hr> <p>Edit:</p> <p>Here is your model interface</p> <pre><code>#import &lt;Foundation/Foundation.h&gt; @interface SARSSEntryModel : NSObject @property (nonatomic, strong) NSMutableArray *allEntries; @property (nonatomic) NSUInteger currentEntryIndex; @end </code></pre> <p>Here is model implementation</p> <pre><code>#import "SARSSEntryModel.h" @implementation SARSSEntryModel @synthesize allEntries = _allEntries; @synthesize currentEntryIndex = _currentEntryIndex; // instantiate on-demand - (NSMutableArray *)allEntries { if (!_allEntries) { _allEntries = [[NSMutableArray alloc] initWithObjects:@"http://www.google.com", @"http://www.yahoo.com", @"http://www.bing.com", nil]; } return _allEntries; } </code></pre> <p>Here is EntriesViewController interface</p> <pre><code>#import &lt;UIKit/UIKit.h&gt; #import "SARSSEntryModel.h" #import "SAWebViewController.h" @interface SAEntriesViewController : UITableViewController @property (nonatomic, strong) SARSSEntryModel *model; // this is your model @end </code></pre> <p>Here is EntriesViewController implementation</p> <pre><code>#import "SAEntriesViewController.h" @implementation SAEntriesViewController @synthesize model = _model; - (void)viewDidLoad { self.model = [[SARSSEntryModel alloc] init]; [super viewDidLoad]; } - (void)viewDidUnload { [self setModel:nil]; [super viewDidUnload]; } #pragma mark - Table view data source - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.model.allEntries.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"cell identifier"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; // Configure the cell... cell.textLabel.text = [self.model.allEntries objectAtIndex:indexPath.row]; return cell; } #pragma mark - Table view delegate - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { self.model.currentEntryIndex = indexPath.row; SAWebViewController *wvc = [self.storyboard instantiateViewControllerWithIdentifier:@"WebViewControllerIdentifier"]; wvc.model = self.model; [self.navigationController pushViewController:wvc animated:YES]; } </code></pre> <p>Here is WebViewController interface</p> <pre><code>#import &lt;UIKit/UIKit.h&gt; #import "SARSSEntryModel.h" @interface SAWebViewController : UIViewController @property (nonatomic, strong) SARSSEntryModel *model; @property (weak, nonatomic) IBOutlet UIWebView *webView; @end </code></pre> <p>Here is WebViewController implementation</p> <pre><code>#import "SAWebViewController.h" @implementation SAWebViewController @synthesize webView = _webView; @synthesize model = _model; - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. // for testing. to prevent conflict with one touch swipe UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(navigate:)]; [self.webView addGestureRecognizer:swipe]; swipe = nil; } - (void)viewDidUnload { [self setWebView:nil]; [self setModel:nil]; [super viewDidUnload]; // Release any retained subviews of the main view. } - (void)viewDidAppear:(BOOL)animated { [self loadURL]; [super viewDidAppear:animated]; } - (void)loadURL { NSString *urlString = [self.model.allEntries objectAtIndex:self.model.currentEntryIndex]; NSURL *url = [NSURL URLWithString:urlString]; NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url]; [self.webView loadRequest:request]; } - (void)navigate:(id)sender { UISwipeGestureRecognizer *swipe = (UISwipeGestureRecognizer *)sender; if (swipe.direction == UISwipeGestureRecognizerDirectionLeft) { if (self.model.currentEntryIndex &lt; self.model.allEntries.count) { self.model.currentEntryIndex++; } else { self.model.currentEntryIndex = 0; } } else if (swipe.direction == UISwipeGestureRecognizerDirectionRight) { if (self.model.currentEntryIndex &gt; 0) { self.model.currentEntryIndex--; } else { self.model.currentEntryIndex = self.model.allEntries.count - 1; } } [self loadURL]; } @end </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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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