BlackSheep
BlackSheep

Reputation: 1087

Pass information from popover table to a web view

I'm using a ViewController with Button for PopOverView, inside a Popover View I load a Table created only by code and never a TableController in my storyboard.

So I can use the pop-over, I see a Table with content get from a plist, but can't send a information from row selected to a webview in the ViewController. here the code:

My ViewController.m (IBAction) to spawn popover:

- (IBAction)popover:(id)sender {

    SAFE_ARC_RELEASE(popover); popover=nil;

    //the controller we want to present as a popover
    RADTwitterPicker *controller = [[RADTwitterPicker alloc] initWithStyle:UITableViewStylePlain];
    controller.delegate = self;
    popover = [[FPPopoverController alloc] initWithViewController:controller];
    popover.tint = FPPopoverRedTint;
    if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
    {
        popover.contentSize = CGSizeMake(380, 500);
    }
    else {
        popover.contentSize = CGSizeMake(280, 300);
    }
    [popover presentPopoverFromView:sender];
}

Here I say to pop over to show RADTwitterPicker.m, my popover opens and I can choose from table, Now I am trying to send information from PopOver to a WebView in first controller:

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

    if([self.delegate respondsToSelector:@selector(selectedTableRow:)]) {

        RADViewController *detailVC = [[RADViewController alloc] initWithNibName:nil bundle:nil];
        detailVC.twitter = [tweetList objectAtIndex: indexPath.row];
        [self.delegate selectedTableRow:indexPath.row];
    }
}

And to read this in RADViewController.m using this method :

- (void)tweetView {
    [twitWidg addSubview: twitLoad];
    [twitWidg loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[twitter objectForKey:@"web"]]]];
    [twitWidg reload];
    twTimer = [NSTimer scheduledTimerWithTimeInterval:(1.0/2.0) target:self selector:@selector(twiterLoad) userInfo:nil repeats:YES];

}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self tweetView];
}

- (void)selectedTableRow:(NSUInteger)rowNum {
    NSLog(@"SELECTED ROW %d",rowNum);
    [self tweetView];
    [popover dismissPopoverAnimated:YES];
}

But when the popover is dismissed i see nothing on my WebView... Any one has any idea to fix this?

thanks.

Upvotes: 0

Views: 185

Answers (1)

user523234
user523234

Reputation: 14834

After re-read you posting, I saw that what you have missed.

Here are my suggestions to fix it:

A. Modify your delegate to return the twitter object not indexPath.row. Here is your new:

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

    if([self.delegate respondsToSelector:@selector(selectedTableRow:)]) {

        [self.delegate selectedTableRow:[tweetList objectAtIndex:indexPath.row]];
    }
}

Make sure you modify your delegate's declaration to reflex this. (return twitter object not the row number).

B. And here is your new:

- (void)selectedTableRow:(WhateverTwitterClassIs *)twitter {

        [popover dismissPopoverAnimated:YES];
       [twitWidg addSubview: twitLoad];
        [twitWidg loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[twitter objectForKey:@"web"]]]];
        [twitWidg reload];
        twTimer = [NSTimer scheduledTimerWithTimeInterval:(1.0/2.0) target:self selector:@selector(twiterLoad) userInfo:nil repeats:YES];

}

Upvotes: 1

Related Questions