Matching text in UITextField to a list in UITableView - objective-c

In my app I have a text box, a table view, and a database. I want to make it so that when I click on the text box and write something in it, my table view will display the list of words similar or identical to the word or words I have entered into the text field. Please, can anyone provide me a suitable idea for implementing this? Thanks.

Whenever you edit text field, the delegate method textField:shouldChangeCharactersInRange:replacementString: gets called. Use this to fetch records from database and reload the tableview.
See similar post here and apple's sample code here

Related

How can I make command-A select all the NSTextView text in rows in an NSTableView?

So if I have an NSView based tableview and inside the views are NSTextViews which are non-editable but selectable...
how can I get that nice functionality of command-A selects all the text? I don't mean row selection. I have row selection disabled for the tableview. I mean highlighting the text in blue so you can copy it to your clipboard. But not just 1 NSTextView's text from one row, all of them from all the rows.
And in addition to command-A click and drag should do this too. But out of the box it seems I can only select one row's text. Here is video showing problem:
https://dl.dropboxusercontent.com/u/2510380/table.mov
(i keep clicking and dragging but can't highlight text on the next row)
here are two mac apps (skype and gabble) that do this:
https://dl.dropboxusercontent.com/u/2510380/skype.mov
and
https://dl.dropboxusercontent.com/u/2510380/gabble.mov
Assuming they are NOT using WebViews with just HTML inside, how do you get this control over the clipboard? i.e. in Skype you select the text and only the conversation is highlighted, not the timestamp of each message. Also the text copied to the clipboard is formatted very nicely. Can you point me in the right direction to reverse engineer skype?
Unfortunately there's no way to do this easily. This is because only ONE control can be the first responder at a time. This means that, though you can have selection in multiple text views, there are several problems:
Only one text view's text will actually be highlighted with the "live" highlight color; the others will have the gray highlight of non-focused controls.
Copy commands will only apply to the first responder text view.
Drag session starts will be initiated from the control the mouse was actually pointing at (irrespective of first responder) and will only drag that control's text.
In a view-based table view, the controls may not even "exist" for a row not currently displayed, so it'll never get the message unless you forcibly create each row, which could be costly for a large table.
Knowing all this, you might be able to "fake it" by having your controller be complicit in a text view and table view subclass's special handling of a select-all message when it's first responder. On receiving this message, the text view subclass can call super then notify the controller (to get its default behavior AND to let you know it happened), at which point the controller can turn around and send the command to all (existing) text views. Highlighting can be spoofed by overriding the text view's drawing and a drag initiation could defer to a delegate (the controller), which would handle writing ALL the strings from your model to the pasteboard (not even touching the text views in possibly-nonexistent row views). The table view subclass would simply pass the same select-all message to the controller without calling super (and even forcibly making sure nothing is selected before returning for good measure).
I hope this helps. If I've forgotten any of your requirements, let me know.
Try like this:-
First create button programatically then write this code after you create button and also write this code in your load method or awakefromnib method.
NSButton *Buttn=// alloc initwithframe;
[Buttn setKeyEquivalentModifierMask:
NSCommandKeyMask];
[Buttn setKeyEquivalent:#"A"];
[Buttn
setAction:#selector(yourmeth:)];
[Buttn setTarget:self];
// now when you press cmd a write
below code in action method
- (void)selectRowIndexes:(NSIndexSet
*)indexes byExtendingSelection:
(BOOL)extend

UITableView Cell - Edit?

Is it possible to use a UITableView to be able to enter a value into a database's field.
For example, if I was to have a UITableView pointing to a field within a database and if I wanted to enter a new entry into the database - tap on the UITableView Cell that would then allow keyboard input into the cell which ultimately end up being a new record in the database??
This is possible, but if something is possible doesn't mean you should be doing so.
You might ask why?
Well! you are trying to input data from view directly to database, this is a very bad practice. There are many reason for it being bad, the major is efficiency and security reasons.
You should consider using MVC pattern.
Now since its completely possible, I will explain the idea on how to do it and conclude with links that will have real code examples.
In tableView:cellForRowAtIndexPath:
add a TextField with tag (to get the reference back in future) and add it to contentView of the cell and have it hidden.
Now in tableView:didSelectRowAtIndexPath: make the cells editing property to YES.
Then, in tableView:willBeginEditingRowAtIndexPath:
get the reference to the textfield in contentview using viewWithTag: method and hide the textLabela and unhide the textfield.
In textfield's delegate textFieldDidEndEditing: make cell's editing property as no (yea, you need to keep the reference) unhide the textlabel and hide textfield.
In tableView:didEndEditingRowAtIndexPath: write methods which will commit the changes to your db.
Below are list of links which will get you code examples:
Having a UITextField in a UITableViewCell
Accessing UITextField in a custom UITableViewCell
iOS Database Tutorial
There are no examples for your requirement 'coz it bit bad way of doing things.
Yes its possible....
You can use delegate methods to take data form you cells textfield to your parent view controller and then save data in database.

List with 3 columns editable on the fly

I want to add in an iOS App a list with 3 columns, but I also want that each field could be editable on the fly by clicking directly on it and when I press return it saves the field.
Currently I am using Xcode 4.6.1 and storyboard.
Here is the idea:
Because I am a beginner, I am asking you if there is a way to do that by using the UITableViewCell, UITextField and UITextView or there is something else to create this list faster.
Can you provide me some links with tutorials or similar, please?
Another question is: because each field (Label1,1; Label1,2; L1,3) will refer to the same object (eg.: cable; [size]1 meter; [diameter]1 cm), is it better to put each row in a NSMutuableArray or put everything in a SQLLite Database?
Hope in some hints.
You can create custom cell. I answered how to do it here
And add gesture recognizers for each object on the cell.
Change values and reload data.

UITextField - Action on resignFirstResponder -- possible?

I have created a form that has a number of text fields that save to NSStrings that are then used deeper in the app.
Currently, if you hit the return key (done) on the GUI keyboard, the keyboard is dismissed, and the data in the text field is saved to its NSString. Likewise, if the background is touched the same occurs.
However, if I touch another text field, without doing one of the above first, the variable is not saved. Is there a way to do this? Perhaps a way to perform an action when a specific text field release firstresponder?
The best solution for your issue is just to use the
-(void)textFieldDidEndEditing:(UITextField *)textField
And then you can just access the textField and store the textFields text in the appropriate string every time focus is lost.

UITableView + UITableViewCell when UISegmentedControl is pressed

I want to ask a question about UITableViewCell.
Apparently, this is what I want to achieve.
I have a page where I display one question at one time. So, when the UISegmentedController on the top right is pressed, I display another question and so on.
please see the picture attached or here: http://dl.dropbox.com/u/27303579/StackOverflow.jpg
Note that I use UITableView (Group style) to display my question. The question text is actually the Section Header.
*All the questions come from Web Service.
My question is:
What should I do when the NEXT (TOP RIGHT CORNER) button is pressed ? What can I do to refresh my page ? Do I need to reuse the current UITableView or how ?
Thanks a lot for your help guys. I hope I make myself clear. really appreciate it !
When the arrow is pressed you can update the data in whatever data structure you have that populates your table cells, and then call [self.tableView reloadData]. This will trigger the UITableViewDataSource functions again, using the data structure to repopulate your table. Of course, cellForRowAtIndexPath will need some handling so that it knows how to draw the cells based on what data they are supposed to display.