Trying to make a tabbed browser - macos

I'm having a problem with cocoa, when I run the app the tabs get added as expected, but all the web views take the same string from the url field.
Basically, if I go to google on one tab, it goes to google on all of them.
Is there any way to make only the web view on the selected tab respond, and not on the others?
Here is the code:
- (IBAction)newTab:(id)sender {
NSTabViewItem *item = [NSTabViewItem new];
[item setView:_webView];
[item setLabel:#"New Tab"];
[_tabView addTabViewItem:item];
}

It looks like you're creating a new tab and then moving your WebView to it. To create a new web view for each tab, you have some options but one is to use NSViewController:
If you create the web view in the same xib as the tab view, move it to a separate xib. Change the class of the owner of that xib to NSViewController.
When adding a new tab in your code, load the xib (assuming it is named WebView.xib):
- (IBAction) newTab: (id) sender
{
NSTabViewItem *item = [[NSTabViewItem alloc] init];
NSViewController *viewController =
[[NSViewController alloc] initWithNibName: #"WebView" bundle: nil];
WebView *webView = [viewController view];
[item setView: webView];
[_tabView addTabViewItem: item];
[_webViewControllers addObject: viewController]; // Store the view controller, remove when the user closes the tab.
}
Here's a tutorial on view controllers: http://comelearncocoawithme.blogspot.fi/2011/07/nsviewcontrollers.html

Related

Using UIRefreshControl with UISearchBar search results

I'm trying to get a behavior like the Mail app where there is a UISearchBar and you can pull to refresh the search results. Currently, I have the Search Display Controller with the UISearchBar connected in IB and everything works fine (I can refresh when in the main tableview and I can search).
But when I search and try to pull to refresh the search results (like the mail app), there is no UIRefreshControl. Check the video below:
Screen Recording
I guess I have to make the UISearchBar the headerView of the tableView but I can't reference the UISearchBar since it's an outlet of the Search Display Controller in IB. Here is my code for the UIRefreshControl :
//Pull to Refresh
refreshControl = [[UIRefreshControl alloc] init];
[refreshControl addTarget:self action:#selector(pullToRefresh)
forControlEvents:UIControlEventValueChanged];
[self.carTableView addSubview:refreshControl];
I'm using the above code in the -viewDidLoad method of the UIViewController that contains the tableView
I solved the problem by creating another UIRefreshControl and adding it to the UISearchDispayController every time the user type a search text in the search bar which I can detect in - (void)searchDisplayController:(UISearchDisplayController *)controller didLoadSearchResultsTableView:(UITableView *)tableView . Here is the code:
//in viewDidLoad
//Pull to refresh in the search
searchRefreshControl = [[UIRefreshControl alloc] init];
[searchRefreshControl addTarget:self action:#selector(pullToRefresh) forControlEvents:UIControlEventValueChanged];
Then:
//in - (void)searchDisplayController:(UISearchDisplayController *)controller didLoadSearchResultsTableView:(UITableView *)tableView
//add the refresh control to the search display controller tableview
[self.searchDisplayController.searchResultsTableView addSubview:searchRefreshControl];

Xcode close view controller

I have two viewControllers parent and child, from parent I'm opening child viewController like this:
ClildVC *modal = [[ClildVC alloc] initWithNibName:nil bundle:nil];
modal.modalPresentationStyle = UIModalPresentationPageSheet;
[self presentModalViewController:modal animated:YES];
and when I return from child View to parent, I use this:
[self dismissModalViewControllerAnimated:YES];
I want, when returning to parent viewController it be refreshed (reloaded), like I open it first time.
in your parentViewController in .h and .m add method
- (void)refreshData
{
//refresh your data
}
in your childViewController type this
- (IBAction)backToParent
{
YourParentController *parent = (YourParentController *)self.parentViewController;
[parent refreshData];
[self dismissModalViewControllerAnimated:YES];
}
dismissModalViewControllerAnimated: is deprecated as of iOS6
You should use dismissViewControllerAnimated:completion: which was introduced in iOS5 in the child view controller after calling a data update on its parent view controller
You are initiating with no nib file and no bundle identifier.
So its looking for a non existent nib in a bundle that isn't there
either design the nib in IB (xcode 4) or storyboard (4.2 +) or programatically by using the designated initialiser for the modal view controller.

Switching of one view to another view in single customViews

I am having of one CustomView in one xib and two different views in two different xib's.
I want to display those two view one after the other in one single CustomeView.
I have an object of NSView which is connected to CustomView in .xib file
#property (retain) IBOutlet NSView *mySubview;
#property (retain) NSViewController *viewController;
Method to open one View is:
-(IBAction)selectBookTicket:(id)sender
{
//setting status label to nil
_viewController=[[NSViewController alloc] initWithNibName:#"BookTicket" bundle:nil];
//loading bookTicket xib in custom view of NormalUserWindow
[_mySubview addSubview:[_viewController view]];
}
Method to open another view in same CustomView is:
-(IBAction)selectTicketCancellation:(id)sender
{
_viewController=[[NSViewController alloc] initWithNibName:#"CancelTicket" bundle:nil];
//loading CancelTicket xib in custom view of NormalUserWindow
[_mySubview addSubview:[_viewController view]];
}
When I am opening any view for first time its displaying properly in CustomView, but when I am trying to open second view or same view for second time then its get overlapping on previous opened view.
I tried
[_mySubview removeFromSuperview]
It's removing 'mySubview' completely, I mean what ever the view is currently loaded it is get removing but it's not allowing to display any views after that '[_mySubview removeFromSuperview]' get executed.
You must remove only the view that you have added from the view controller. Try the following code instead.
-(IBAction)selectTicketCancellation:(id)sender
{
[[_viewController view] removeFromSuperView];
_viewController=[[NSViewController alloc] initWithNibName:#"CancelTicket" bundle:nil];
//loading CancelTicket xib in custom view of NormalUserWindow
[_mySubview addSubview:[_viewController view]];
}
Executing [_mySubview removeFromSuperview] will remove your host view (i.e; the one that is displaying views from other view controllers) from view hierarchy and this explains the "not allowing to display any other subviews part".

How to add the Navigation Bar's view to a PopOver's PassThroughViews?

I have a PopoverController view that allows a user to download a file. On button press, the popOver view will expand in size, display download status, and the main view controller will be obscured by an unhidden "cover" view that has been added to the PopoverController's "passThroughViews" property so that the user can not accidentally dismiss the pop over while the file is downloading.
My problem is that, in storyboards, my main viewController is embedded in a Navigation Controller. I can't seem to cover the navigation controller's bar with a view in the storyboard, and if the user presses anywhere on the navigation bar then the popover will disappear and the user will lose the download's progress bar.
How do I either cover up the navigation bar with my "cover" view, or how do I add the navigation bar's view to my popOverController's passThroughViews?
Opening the Popover from the main viewController:
- (IBAction)openDataOptionsPopOver:(id)sender
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
PopOverViewController *optionsWindow = [storyboard instantiateViewControllerWithIdentifier:#"dataOptions"];
self.popUp = [[UIPopoverController alloc] initWithContentViewController:optionsWindow];
[self.popUp setDelegate:self];
[nextNavButton setEnabled:NO]; //Disabling barButtonItem on the navigationController
optionsWindow.containerPopOver = self.popUp; //Pointer to the popover, to resize it later.
optionsWindow.coverView = self.coverView; //Pointer to the coverView, to (un)hide later
[popUp presentPopoverFromRect:[sender frame] inView:[sender superview] permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
}
Setting the passThroughViews property inside of the PopoverViewController:
//Expands the popOver on press of "refreshFileButton" to display progressView
-(void) explodeWindow
{
//setting self.navigationController.view and ...visibleViewController.view here didn't seem to work ...
[containerPopOver setPassthroughViews:[NSArray arrayWithObjects:coverView, nil]];
[containerPopOver setPopoverContentSize:CGSizeMake(600, 400) animated:YES];
[titleBarItem setTitle:#"Downloading File. Please Wait ..."];
[refreshFileButton setHidden:YES];
[progressView setHidden:NO];
[downloadLabel setHidden:NO];
[coverView setHidden:NO];
[progressView setProgress:0.0 animated:NO];
}
I've tried adding self.navigationController.view to passThroughViews with no success--it actually turns out to be a null pointer. And I can't seem to place a UIView at any level in storyboards that will cover all my controls without obscuring the popOver. What am I missing here? And thanks for reading.
Edit:
As Aglaia points out below out, implementing the following, and avoiding passThroughViews, is probably the best way to do this.
- (BOOL)popoverControllerShouldDismissPopover:(UIPopoverController *)popoverController
{
//Don't dismiss our popover when the view covering our controls is present
if([coverView isHidden]){
return YES;
}else{
return NO;
}
}
Maybe there is something I am missing, but why don′t you just implement a new view controller with its navigation bar set to none and present it modally on button press? Then when the download is finished you just dismiss the view controller.
If you want the user to see the underlying view you can use a UIAlertView instead.
Alternatively set you view controller as the delegate of the popover controller and forbid the user to dismiss your popover on touch outside through
- (BOOL) popoverControllerShouldDismissPopover:(UIPopoverController *)popoverController
{
return NO;
}
Then when you want to dismiss it call dismissPopoverAnimated:
to cover the whole screen including navigation bar:
[myView setFrame:[[UIScreen mainScreen] bounds];
[self.navigationController.view addSubview:myView];

iOS5 Xcode: using a link within a web view to open a new view within app

Within one of my views, there is a webview that I load in a html page locally. Within this page I have a link (href) that when pressed it opens a view within the application and not a with in the webview/current view.
For example I have a button on this page that if pressed opens another view, is there any way I can do the same within a webview using a normal link?, the code I use for this button is below so is there away to get the href link in the web view link to similar code to open my new view up??
The link in the webview is a normal See view ???
#import "anotherview.h"
.....
-(void)myhereflinkBtn:(id)sender{
anotherview *newviewPage = [[anotherviewhehffvv alloc] initWithNibName:nil bundle:nil];
[UIView transitionFromView:self.view
toView: newviewPage view
duration:1.0
options: (UIViewAnimationCurveEaseInOut | UIViewAnimationOptionTransitionCurlUp)
completion:^(BOOL finished){}];
}
I hope this make sense.
Well with a bit of looking and a fresh face this morning I have manged to get 90% of what I am after working:
Using this link as help CLICK HERE i have managed to get my xcode register my link press
- (BOOL)theWebView:(UIWebView*)theWebView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
if(navigationType == UIWebViewNavigationTypeLinkClicked) {
NSLog(#"LINK CLICKED:");
[webView stopLoading];
return YES;
}
return YES;
}
- (void)viewDidLoad
{
webView.delegate = self;
[super viewDidLoad];
}
Within the header file I also then added < UIWebViewDelegate >

Resources