Is there a way to update the NavigationTitle of a NavigationView from a button in it's detail view? - swiftui

I have a NavigationView showing a title with the number of records in a List:
.navigationTitle("\(navBarTitle) (\(String(numberOfRecords)))")
In the toolbar I have 2 buttons:
show Unread - only show unread / show all
show Favorites - only show favorites / show all
The List view shows either All records, Unread records or Favorite records. Switching between Views using the buttons works fine and updates the navigation title numberOfRecords variable.
All is well sofar. Now...
Rows in the list have a NavigationLink that goes to a detail view:
NavigationLink(destination: detailView(record: record))
In the detail view I have a button: make card favorite. I click the button, but when returning to the list view, the numberOfRecords variable in the navigation title is not updated.
How can I update the navigation title from its detail view?
Thank you!

Related

SwiftUI Searchable several views down from NavigationView?

I'm having problems related to .searchable and am wondering if it's related to my application's view hierarchy. The examples I can find for using Searchable say to use it on the NavigationView directly, and show it like so:
var body: some View {
NavigationView {
List {
...some list content here...
}
.navigationTitle("My List")
}
.searchable(text: $queryString)
}
My NavigationView is a couple of views up from the list where I want to use .searchable. My hierarchy:
HomeView (has the NavigationView) -> LocationsView -> LocationListView
I want to use .searchable in the LocationListView, and I can - but it's not optimal. The Search bar is always visible, and it causes the navigation bar in my LocationDetailView (the next view down the hierarchy) to "jump" down when the view loads, and crowd the rest of my view, with a gap at the top.
Link to image w/nav title gap
I theorize that this is because I'm using .searchable in the LocationListView, which is inside the NavigationView. If I comment out .searchable in the List view, the Detail view does not have this behavior.
I'm wondering if there is a good recommendation for how to deal with this. I know I can't use a second NavigationView in the ListView, because then it's nested inside the first navigation view and has all of the associated issues. (Although it does fix the .searchable implementation!) Is there another way to solve this?

How to assert on the text in a DatePicker which has the compact style?

I am rendering a DatePicker in my application with the compact style as follows:
DatePicker("Date Selected", selection: $selectedDate, displayedComponents: [.date])
.accessibilityIdentifier("DatePicker")
.datePickerStyle(.compact)
I am able to tap on the DatePicker in a UI test, select the date that I want in the calendar-style popup, and then dismiss the popup as follows:
// 1. Show the DatePicker popup
application.datePickers["DatePicker"].tap()
// 2. Choose a date in the popup
application.datePickers.collectionViews.buttons["Friday, January 14"].tap()
// 3. Dismiss the DatePicker popup
application.datePickers["DatePicker"].tap()
(All of the above is demonstrated in this sample application.)
Is it possible to assert that the DatePicker is now showing the date that I selected? If so, how?

How do I change what the digital crown scrolls, if there are multiple scrollable Views?

In my case there is a Picker capsulated in a ScrollView. In the beginning the Picker isn't visible, so I wish that the Crown would scroll the ScrollView until the Picker is visible and selected via touch.
What it does right now, is trying to scroll within the Picker and changes its value, when the crown is rotated. The user has to scroll down a bit, so the Crown selects the ScrollView to scroll.
Here a simplified code version of mine:
ScrollView {
ButtonView(data: self.data) //is longer than the screen.height
Spacer()
PickerView(data: self.data) //includes the Picker
Spacer().padding(.top)
NavigationButtonView(data: self.data)
}

UITabBar item did select is not working

i have two tab bar items with two different table view with navigation controllers.
by clicking on the tab1--- table1 is opening...Good. but when i did select on table1 it goes to the another view (table did select view)....every thing is good.
but the problem here is
when i am clicking on tab2 ----table 2 is opening....Good.
But again clicking on tab1------ it is not loading the table1....it is loading (table did select view) view. As the last time i left it there.
i want to open table1----on clicking on tab1......by programming.
help me
That is the expected behaviour if you are using the tab bar controller and the navigation controller in the item of the tab bar. User will expect the tab to retain the state of the view.
If you still want to enforce the app to go back to the root view controller of the navigation controller when user goes back to the tab, you can implement the UITabBarControllerDelegate tabBarController:didSelectViewController: method. What this delegate method does is:
Tells the delegate that the user selected an item in the tab bar.
Then call the method of UINavigationController called popToRootViewControllerAnimated: when user tap on the tab. This will help you to:
Pops all the view controllers on the stack except the root view
controller and updates the display.
For example:
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
if(viewController == yourNavigationController) {
UINavigationController *navigationController = (UINavigationController *)viewController;
[navigationController popToRootViewControllerAnimated:NO];
}
}

Sencha Touch 2: Multiple instances of a NavigationView (one for each tab) : every panel pushed by controller opens in first tab

In my sencha touch app i have a NavigationView container which loads a panel view containing a list rendered from a store.
I have a tab-bar in which each tab opens this NavigationView container adding, depending on which tab is tapped, some extraparams in the store used by the panel view inside the NavigationView container.
This is working OK and for each tab i get the NavigationView container and inside it the panel view containing the right list for that tab.
The problem is these lists have some child lists that need to be loaded when tapping a list item. I do this using the following controller that pushes in the NavigationView container another view Panel containing the child list:
Ext.define('FirstApp.controller.Details', {
extend: 'Ext.app.Controller',
config: {
refs: {
// this is my NavigationView container
placesContainer:'placesContainer'
},
control: {
'placesContainer categorie list':{
itemtap: 'chooseCategory'
},
And my chooseCategory function is:
chooseCategory:function(list,index,target,record){
//these add some extra params to my store's proxy
Ext.getStore('Articoli').getProxy().setExtraParams({ catid: record.data.id });
Ext.getStore('Articoli').load();
this.getPlacesContainer().push({
// this is the target view panel
xtype:'articoli',
title:record.data.title,
data:record.data
})
}
And this works very well but when you click on a list item, its child list is pushed inside the first tab panel.
Example: i tap on the 3rd tab. The app shows the list corresponding to the 3rd tab. I tap on one of the list's items. The app loads its child list in 1st tab panel. I cannot see any changes until i tap on the first tab. There i can see loaded the child list of tab 3.
You can give onDisclosureItem:true to your list and in the controller give an disclose event so that on disclose it would load the sub categories and on item tap it would navigate you to the other view
'placesContainer categorie list':{
itemtap: 'chooseCategory',
disclose: 'openSubCategory'
},