user777304
user777304

Reputation: 455

trying to make tabbed uiwebview browser need help xcode

I am trying to make tab browser just like safari or chrome with tabs. when user open new url, webview will be added to array. and when user tap on button then openLoadedWebview: will called and remove the original webview and open a loaded webview from array.

But it is not happening. things working are: webview removefromsuperview works. wv succesfully added to self.view. with index number issue: new added wv is same as webview with same url.

any better idea or approach... I am totally new...

mainViewController.h

 @interface mainViewController : UIViewController <UITextFieldDelegate, UIWebViewDelegate>
    {
        UIWebView *webView;
        UIWebView *wv;
    }
    @property (nonatomic, strong) NSMutableArray *array;

mainViewController.m

- (void)viewDidLoad
{
    [super viewDidLoad];
    webView = [[UIWebView alloc]init];
    webView.frame = CGRectMake(10, 130, 300, 400);
    webView.delegate = self;
    [self.view addSubview:webView];
}


-(BOOL)textFieldShouldReturn:(UITextField *)textField {


    textField.text = [self repairURL:textField.text];
    NSURL *url = [[NSURL alloc] initWithString:textField.text];
    NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];
    [webView loadRequest:request];
    [array addObject:webView];

    return true;
}

-(void)openLoadedWebview:(NSString *)pageLabel

    if ([cell.label.text isEqualToString:@"Trending"]) {
                NSLog(@"Selected Cell: %@", pageLabel);
            NSLog(@"number of objects %d", [array count]);
           // wv = [[UIWebView alloc]init];

            wv = [array objectAtIndex:0];
            wv.frame = CGRectMake(10, 100, 300, 400);
            wv.delegate = self;
            [self.view addSubview:wv];


        }
      else if ([cell.label.text isEqualToString:@"Rec"]) {

            wv = [array objectAtIndex:1];
            wv.frame = CGRectMake(10, 100, 300, 400);
            wv.delegate = self;
            [self.view addSubview:wv];
        }

[webView removeFromSuperview];
}

Upvotes: 1

Views: 3305

Answers (1)

Hassan Mahmood
Hassan Mahmood

Reputation: 1601

You can use one of these: https://github.com/graetzer/SGTabs https://github.com/xxhp/BrowserTabViewDemo

I think this is what you are wanting to achieve: https://github.com/fictorial/BHTabBar

Upvotes: 4

Related Questions