I'm having this problem regarding the displaying and updating of the username label.
User id 1 - ‘Felicia’
User id 2 - ‘Sam’
(1st screen: default user is 'Felicia')
(2nd screen: when change user to 'Sam')
(3rd screen: after clicking to another screen, the username's label auto revert back to 'Felicia' when it supposed to be 'Sam')
My ideal output is that the username's label will stay as the selected user unless user is changed and also to be able to reflect the name label on the side menu bar whenever the name is updated.
In my codes, I tried adding my methods(getUserInfo() and setUserNameLabel()) in viewDidAppear and viewDidLoad, however both scenarios are not generating the output I want.
viewDidAppear
Advantages:
- Name label will reflect the update of selected user's name (User can change their name)
Disadvantages:
- Name label will revert to the user id 1’s name on side menu bar when selecting other views
viewDidLoad
Advantages:
- Name label won’t revert to the user id 1’s name on side menu bar when selecting other views
Disadvantages
- Name label won’t reflect the update of selected user's name
You need to create delegate or use NSNotificationCenter for trigger name change event in side menu viewcontroller .
Because while you create side menu so that in this class viewDidLoad or any other method called once during life cycle .
Example for do this through NSNotificationCenter.
https://stackoverflow.com/a/24756761/3901620
work around: what about viewWillAppear or viewWillLayoutsubviews
I thinks viewWillAppear or viewWillLayoutsubviews (in case you use autolayout) is what you need.
When you switch from Felicia to Sam, you must save that state to somewhere to refer when you reopen your side menu.
pseudocode code:
var selected = Felicia
if `Felicia` clicked:
selected = Felicia
if `Sam` clicked:
selected = Sam
(save selected to somewhere like NSUserDefault)
And in your side menu viewWillAppear: change the UI with selected user.
load selected (from somewhere like NSUserDefault)
if selected == `Felicia`
do UI update at main thread
if selected == `Sam`
do UI update at main thread
Take a look at UIViewController lifecycle:
Related
Heloo all,
I am new to ios swift. I have one problem in my screen.
I have one screen with drop down list of option like : current bill,water bill., bike bill, loan bill, phone bill....so on
I have sone this. But what i need is, whenever i select any option from drop down list. I need to show some ui elements like label, text filed, text box, lie that dynamically for each each selction in drop list.
For example :
if i select water bill, then below my drop down, i need to show the two label ui with name , id.
if i select current bill , then below my drop down , i need to show one text filed with place holder ' enter current bill number'
So like wise when ever i select any option from drop down..i need to show some dynamic ui.
How can i achive that ??
ANY HELP WILL BE USE FULL
You can make use of container views to achieve that:
1- Add your drop down menu to any view controller you want.
2- Add a container view under that drop down menu and using auto layout make that container view fill the place that you want it to be switchable/dynamic.
3- Redo step 2 as many times as the items of the drop menu.
4- Create IBOutlets for each of your container views and and an IBAction for your drop down menu.
5- In the IBAction of your drop down menu, set isHidden property of one container view to false and set it to true for the others based on the user's selection from the drop down menu.
Here is a tutorial that explains that with a simple example.
Just drag and drop viewcontrollers in your storyboard for your current bill,water bill., bike bill, loan bill, phone billetc.
And when ever you change the option from your drop down list use below code to add your required controller as child controller.
let currentBill = self.storyboard?.instantiateViewController(withIdentifier: "currentBill") as! CurrentBillVC
// remove other views
for k in 0..<self.parentView.subviews.count {
self.parentView.subviews[k].removeFromSuperview()
}
self .addChildViewController(currentBill)
// Add view to your maincontroller i named it parent view in which you want to display other controller w.r.t your drop down list.
self.parentView .addSubview(currentBill.view)
currentBill.didMove(toParentViewController: self)
I have a navigation controller stack where one of the views has a dynamic title.
The view controllers and their titles go like this:
Main --> ItemsTableView --> ItemDetails
Title:Main Title: NN Items Title: Details
Because the iOS UINavigationController sets the text of the "Back" button to be the title of the previous screen, the "Back" button on the details screen says "< NN Items" where NN is a dynamically changing number.
I'm trying to do some iOS UI automation, but the accessibility Label / ID of the back button is set by the system to it's button text. This means that the accessibility label of the back button on the details screen will change dynamically, and I can't find it from my scripts!
If I could get a reference to the UIBarButtonItem then I could easily set it's accessibilityLabel or accessibilityIdentifier from code to be a fixed string, however I can't figure out how to do this?
All of the stuff I've been able to find references setting the back button to a custom button via self.navigationItem.backBarButtonItem or similar, but when I read this property it's nil. I haven't been able to find out how to get access to the standard item without replacing it. I'd prefer not to replace the button if possible
This was bugging me as well. I've been writing Xcode 7 UI Tests and was trying to come up with a generic way of tapping on the back button without having to replace it with a custom button.
The following is how I solved this for Xcode 7 UI Tests - but you may also be able to apply this to UI Automation as well.
I discovered that (in terms of Xcode 7 UI Tests at least) the back bar button item that is created by the system consists of two buttons the entire thing is a button with an accessibility label of whatever the title of the button is, and then the arrow is also a button with an accessibility label of "Back".
Thus, as long as there aren't any other buttons on the screen that are identified as "Back", the back button can be accessed via the accessibility label of "Back". Like so in the case of UI Tests:
[[app.buttons matchingIdentifier:#"Back"] elementBoundByIndex:0]
Here I'm getting the first button that can be identified by "Back". I my case there could only ever be two such buttons - the arrow, or the whole back button itself (in the case where the back button's title is also "Back"). Since both of these buttons are essentially the same, just getting the first one it finds is sufficient.
I have a simple application which has a Table View (TV1) which gets populated by the user selecting a navigation bar button item to Add Entry (VC1). Within the Add Entry, when the user presses the Name field, they're taken to another Table View (TV2) which serves the purpose of allowing the user to select a previously entered name or create a new name.
TV2 is a Table View Controller with a Search Bar at the top.
Right now, existing names are available and show to the user. However, if the user "searches" for a name that does not exist, they should have the option to Create that name right now. If a search does not exist, I have a button which the user can tap which will create the user. That's simple. However, it's another tap.
Is there a way I can get the Search button of the Keyboard to perform the same functionality of the create button (i.e. Save the new user and dismiss TV1) which would then allow me to remove the Create button in the middle of the table view?
try this:
searchBar.delegate = delegateInstance;
//delegateInstance.m
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar{
//perform the same functionality of the create button
}
You can catch the event fired by tapping the search button this way :
UISearchDisplayController has a UISearchBar, you can set a delegate
for search bar and implement -searchBarSearchButtonClicked:.
From now, you should be able to call the same treatment that you do on create button. Found this answer on this post. Hope that helps !
I don't think you can find a right keyboard ReturnKeyType for "Create" or "Add" to let user know the return key of the keyboard will create a user. =)
Anyway, I guess what you want is if you click "search" button second time with no search result displayed on the tableview then you want to create a user with new search text on the search bar. Did I understand right? If so, I think I already answered your question.
In UISearchBarDelegate, – searchBarSearchButtonClicked:, Check if you don't have any search results and have any text in the search bar, then you can create a user.
I have a simple application which is a table view (TV1) that gets populated by the user tapping the plus button in the navigation bar. The user gets taken to an Add Entry screen where tapping on the "name" text field brings up another Table View (TV2) for the user to add existing entries, search for existing entries or add a new entry. This works really well and delegates ensures that what I select in the new Table view (TV2) populates the Name Text Field.
What I want to achieve is the other way around also; if a user has the name text field already populated and clicks on it to bring up the TV2, I want the search bar to already be populated with the string that was passed through while ensuring the searching still works.
For example, if I have the nameTextField with John, when I click on the nameTextField and get taken to the TV2, I want the searchBar.text to say John, but also for the searching to now only show entries with John in the name, just like it would be if I start typing the name John.
I am using Core Data and NSFetchedResultsController.
In the prepaeForSegue of the Add Entry, I am doing this:
if ([self.nameTextField.text length] > 0)
{
[envylopeNameTextFieldTableViewController setSelectedName:self.nameTextField.text];
}
In the TV2, the setSelectedName method is:
- (void)setSelectedName:(NSString *)selectedName
{
_selectedName = selectedName;
self.nameAddSearchBar.text = selectedName;
[self searchBar:self.nameAddSearchBar textDidChange:selectedName];
}
The last line in there is a trial by me because that method is what gets called when I start searching, so I thought I could call that. I tried it without it and with self.nameAddSearchBar.text = self.selectedName and _selectedName and nothing; the searchBar does not get populated.
With a breakpoint, I can see that selectedName = John and _selectedName = John, but self.nameAddSearchBar.text = nil.
I can imagine I'm one or two lines of code away, but I'm just not sure how to proceed.
Any assistance would be really great.
Thanks,
Try moving
self.nameAddSearchBar.text = selectedName
from the setter (-setSelectedName) into viewDidLoad in TV2. The issue here is that you're trying to assign nameAddSearchBar (a view) before it has loaded.
Since the search bar is part of the "view", it is not be available until "viewDidLoad". You can set the selectedName property with the right value and then update the view (search bar.txt) with that value once the view is loaded (in viewDidLoad).
One of the cells in my DBTreeListView is bound to a repository item that is a progress bar.
I want to be able to edit the progress displayed by clicking on this cell. At this stage my application should change its cell to another repository item: a text field where I'll be able to insert a value. Once focus is changed to another cell, my progress bar should be displayed again, showing a new value. How do I do this?
DBTreeListView has column events OnGetEditingProperty and OnGetEditProperties. I'll probably use one (or both) of them, but can't come up with any good idea.
This can be simply. You should handle click on this progress bar and display editor over it. You need to handle scrolling and clicking in another place to get rid of editor. And in case that scrolling too far - editor should be hidden.
Steps:
Create hidden editor for progress
Handle OnClick for tree view item
Display editor and set focus
On editor enter (or tab) save progress information
On click on form or another part of tree view - hide editor (saving/discarding changes how specified by your policy)
On scroll tree view move the editor and when bounds of parent does not overlap bounds of editor - hide it
Best regards,
Vladimir