I have a screen and a UITableView within it to display some companies information. Every company's area has 1 address text field and an arrow icon followed on UI. Click the arrow icon, contacts of this company will be showed. The data includes name and telephone. These contacts are UITableViewCells as well, which belong to same section. For 2nd company, there is another section.
In every section, below these contacts cell, there is a "Edit/Save" button. user can edit or save contacts' name and telephone by clicking it.
my question is,
I can know which Edit/Save button is clicked by using (id)sender in action method, but how can I read the values of the updated contacts' name/telephone in those 2 text fields just above the button?
Thanks in advance!
the whole table view looks like this,
company1
address [arrow button]
contact's name
contact's telephone
[edit/save]
company2
address [arrow button]
...
Your controller should be the delegate for each UITextField that is used for entering details.
Whenever any text is changed, record it straight away (into a temporary store like a dictionary, using textField:shouldChangeCharactersInRange:replacementString:). You do it immediately so you don't need to worry about completing edits at the end and so that nothing is lost if the table view is scrolled.
If the table view is scrolled and the cells are recreated you can fill in the previously entered value from the temporary store.
Now, when the save button is pressed you use the temporary store of data.
Related
I am trying to do a simple application but I am very new to Xcode and Swift.
I am trying to do an application that has the following functions:
one text
one picture
one button
By pressing the button the text changes into another text, the picture into another picture and the button disappears. All these items must be predefined.
For now, I have one text, one picture, and one button. When I press the button, everything works. The picture changes, the text too, and the button disappears.
Now, how can I update those items every day?
And is it possible to make the button disappear until the next new updated text is shown?
What I mean is that once you pressed the button the first picture will not be shown anymore but it will stuck on the second picture until the new updated text and picture comes out?
Ok so what you can do is,
When user opens your app, you can call a service and check whether you have updated text. If you get response, you can unhide the button and on click of it you can change the data.
Whenever your data gets updated, you can send a silent push notification to your app and store that data. And the next time user opens your app, you can check the data and unhide Button if data is present.
I'm implementing search function on my project. I have three text boxes and a search button
Fist Name
Second Name
Age
Search button generate search on another result page. The problem is that, when I click back button from the result page, Then the Age text box filled with first Name data which I enter previously and first name field remains empty. How did it happen.
I have a table view list and an add button at the top right. The user would press the button and a text field would pop up for a user to enter a string to be the label of the new item. Nothing new or special, what you'd expect from a "new playlist" type situation.
I am looking to have the small text field input that the user would type into. Most examples have the app move to a new view controller with a text field. I simply want a little box to overlay the current view that accepts a string. I cannot find/remember the name of the text box so I cannot find examples or code.
I think you are searching for something like
https://github.com/bmancini55/iOSExamples-DockedKeyboardView
Where your UITextField would be attached on the keyboard's accessory view.
OR
http://nshipster.com/uialertcontroller/
Where you use an UIALertController with an input field. I think the second one will resolve your problem more than the first one, because you are asking for a pop-up solution.
Hope it helps
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).