splitView/Objective C - unable to update detailView from second tableViewController

I am having a splitview application. MasterView is a UITableViewController and the detail view is web view. In the master pane on selecting an entry, another table view (created using one more tableviewcontroller to avoid complexity) appears and detail view shows some page related to the entry. This much is working fine.

Now I want the same with second table view as well i.e. on selecting an entry, the detail view should update accordingly. But its not getting updated. I have made the following function in the first tableViewController class:

-(void) display:(NSString*)theUrl
{    
    NSLog(@"%@", theUrl);
    NSURL *myUrl = [NSURL URLWithString:theUrl];

    NSURLRequest *request = [NSURLRequest requestWithURL:myUrl];
    splitViewDetailViewController *detailViewController = 
    self.detailViewController;

    detailViewController.webView.scalesPageToFit = YES;

    [detailViewController.webView loadRequest:request];
}

I am calling this function from the secondTableViewController and its getting called but detail view isn't getting updated. In the didSelectRowAtIndex method of secondTableViewController I am doing this:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{  

    NSString *urlString=@"http://www.google.com";

    NSURL *myUrl = [NSURL URLWithString:urlString];

    NSURLRequest *request = [NSURLRequest requestWithURL:myUrl];
    splitViewSecondViewController *secondDetailViewController = [[splitViewSecondViewController alloc] init];
    secondDetailViewController.detailViewController=self.detailViewController;

    [self.navigationController pushViewController:secondDetailViewController animated:YES];

    self.detailViewController.webView.scalesPageToFit = YES;

    [self.detailViewController.webView loadRequest:request];
}

But then the following run time error comes: Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSCFConstantString stringByAppendingString:]: nil argument

Answers


TableViewController.h

@protocol TableViewControllerDelegate
-(void)display:(NSString*)theUrl :(NSInteger)index;
@end

id<tableViewControllerDelegate>_delegate;
@property(nonatomic,assign) id<tableViewControllerDelegate>_delegate;

TableViewController.m

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    selectedIndex = indexPath.row;
    [self.ResultTbl reloadData];
    [_delegate display:(NSString*)theUrl :selectedIndex];
}

masterview(splitview).h

#import "tableViewController.h"

@interface MasterViewController : UIViewController <tableViewControllerDelegate>

masterview(splitview).m

-(void)display:(NSString*)theUrl :(NSInteger)index
{
    NSLog(@"%@", theUrl);
    NSURL *myUrl = [NSURL URLWithString:theUrl];

    NSURLRequest *request = [NSURLRequest requestWithURL:myUrl];
    splitViewDetailViewController *detailViewController = self.detailViewController;

    detailViewController.webView.scalesPageToFit = YES;

    [detailViewController.webView loadRequest:request];
}

Need Your Help

How do I best reuse html code for menus

javascript html jsp nav code-reuse

I'm making a larger website using HTML, css, JSP and Java-servlet.

Display AngularStrap Dropdown Manually - How?

javascript html angularjs angularjs-directive angular-strap

I am trying to display an AngularStrap dropdown manually, leveraging the trigger configuration on $dropdownProvider as such