Showing past entries on UITextField - objective-c

I am writing an app in which I have two UITextFields...
Starting Text
Destination Text
Now once I place values and hit the search or whatever function I want to call, I Want to reuse these values. The app should record and save these values as cache. And should show them when typing or upon a button click. Is that possible to show them just like Dictionary words show up or Which is more preferable tableView or PickerView? If there is any other please let me know.

Definitely use a UITableView. A UIPicherView is used modally most of the time and not for optional suggestions.
Table view is used in Safari, and a lots of other apps:
As for how to cache the data, you have lots of options. It also depends on how much data you expect.
One easy way would be to simply use NSArray. You can very easily write an NSArray to disk in a plist file and read it back when you need it.
Or you could use Core Data, if you expect lots of data and still want high performance. It will be a lot more difficult though to get used to that API if you've never tried it before. Basically you'll need a simple model with one entity called something like SearchEntry that has a single property text. Then you keep adding new instances to your managed object context and can easily filter the existing values.

Related

How can I refresh my composable when new data is being inserted?

My team and I have to make a license plate scanning app as a school project. With that, we have comments and pictures which can be added to cargo. Whenever the user scans a plate they also get the chance to change the checked info in case of a mistake. The problem is that whenever we delete data from the scanned plate it doesn't show on the screen that it has been deleted until we go to another screen. The same goes for the lazy column which we use for inserting new instances of comments and pictures. The data doesn't show on screen until we turn our screen or go back to another screen. private val pictureList = mutableListOf() is what we use for the pictures and for the text we use var countryCode by remember { mutableStateOf(CountryCodeText) }
var licenseNumber by remember { mutableStateOf(LicenseNumberText) }. pictureList is a global variable and the other ones are local variables which use global variables in the mutableStateOf. How can we make sure that the UI updates whenever the data changes? In advance I want to say thanks for the help! (Code is written in Kotlin and jetpack compose)
Just replace the mutableListOf() with a mutableStateListOf(...), and prefer to keep all the state logic confined to a ViewModel. The viewmodel should preferably be only one for the entire app, and the entire app should have only one activity.
The viewmodel should act as a single source of truth for the entire activity's UI state, while also handling all the updates to the UI efficiently.
The #Composables should only be incharge of displaying the state, and sending events to the viewmodel to update the state, for example, an onClick event may be sent up to the viewmodel by a button too trigger a state change in another part of the app.
Take this codelab to learn all about state in Compose (Well, not all, really, but good starter).
Also, changing screens destroys all the #Composables of the current screen, and so when you ce back there, all the #Composables are re-created, and the correct data is fetched. If you wish to trigger "recompositions" upon changing a variable, you must ensure that the concerned variable is a state-holder, i.e., initialized with one of the pre-built state initializers, like mutableStateOf(), or mutableStateMapOf, etc.
We usually have a mutableState*Of format for determining whether a pre-built state initializer is available. The most common ones are covered, obviously, but if not, you'll need to create a new type of initializer yourself, and if that is not something you know how to do, currently, you can just go about checking whether the type of data you wish to store is Immutable. If so, you can just wrap it in a mutableStateOf<DataType>() call, and it will trigger the recompositions. Know that this is not as efficient as pre-built initializers, but definitely gets the job done.
Also, I suggest you take the compose-pathway to get the basics down. It covers everything ranging from creating a simple UI using basic pre-built Layouts to creating a complex animation-driven application using custom Layouts.
So, definitely a lot to take it, but I hope you get there.
Happy composing,

What is the best way to work with C++ model and TableView?

I rather newcomer in QML and can't find the best solution to work with QML TableView regarding C++ models. Almost all google's links say that I should use QAbstractTableModel. However, the problem in using this model (or better to say Presenter) is that I shoud emit dataUpdated every time anything is changed in real data.
But my approach is to create RowPresenter with QObject-derived properties for every column-cell (e.g. NameCellPresenter, StatisticsCellPresenter etc.) All these cell objects have complex data and it should be displayed in cell via properties. Moreover, I could display several types of data in one cell. And nobody, except these cell presenter objects, will never know about changing (RowPresenter or List of RowPresenter will only do their function of creating/removing...)
The questions are:
How could I efficiently update to QML the number of rows and rows from QList<RowPresenter> (without resetting ContextProperty) ?
Are there any methods to work with QAbstractTableModel in such way: only cell presenter knows about changing, and displaying complex data in one cell that could be changed independent from different threads?

Simplest possible way to show two items NSTableView from code?

How I can create a code in XCode 4.2.1 what will create NSTableView and add just couple of items to it?
All what I wanted to do is:
1) Window where is NSTableView
2) I have an array of strings in NSArray which I like to show in that NSTableView
3) All of this should be done in code. So I don't want to learn how to add this action happen when you press button (I know already how to do actions when user click buttons etc), I just want that application launch -> draws the table where is those items from my array. That's it, nothing more.
And yeah I have understood that I do not add items to NSTableView directly. That is not the point in this question. I just mean that I want to show couple of items in that table but I have no and kind of clue WHERE I should add my data from my array.
I have tried to google for example pages for hours (just too many and have not find help) but I will always be stucked in the part when
a) I must do something in the Interface Builder and the images of the interface builder are from version 2.x or 3.x and I have 4.2.1 and it is totally different (new to XCode...). Surely I have drawn my TableView element to UI but I mean delegations etc. Are those necessary at all? Can those be made from source code?
b) Code just does not work anymore because language (Cocoa or Objective-C, I don't know) has changed and I don't know how and what I have to do to make it work on newest version of XCode.
c) There is too much different ways told: "use binding", "you must create new class what is NSTableViewDataSource" etc. I have no any kind of clue what is preferred way, is another way optional or it is "you should use this because another is going deprecated soon" or something.
So please, can somebody give help in step-by-step what I exactly have to do? Should I create some bindings? If so, how and where? Do I have to create DataSource component myself? Are those ways valid any more? If I have to, how I can create it? Create a new class and implement it as a NSTableViewDataSource and then use it? Is that way valid any more and if it is, can sombody show code what is as simple as possible?
I have also checked Apple Documentation page many many times, checked those example codes but there is just too much totally unrelated stuff that I just don't understand at this point so they are totally useless (I mean, I don't know what is required for this task, what are not etc.
I would be very happy if somebody can help short tutorial step-by-step what to do. I mean "step-by-step" like:
1) Create new project
2) Draw NSTableView in project
3) Create new class with this name
4) Write this code: blah blah blah
5) Create another class with this name
6) Write this code
7) Run and see those items from array in NSTableView using (bindings/datasource/whatever is preferred).
Thanks :)
Your tableview needs a datasource. Your datasource is a custom class, it implements the "NSTableViewDataSource" protocol. This protocol contains a few methods that you can use to tell the tableview what data you got.
this includes the objectValue ( the value of the NSCell that is displaying your data on the specified row, and a method that returns the amount of rows the tableview has ( the amount of items in your array ).
Here a tutorial I found by googling:
CocoaDev.com NSTableView tutorial
You can also implement the NSTableViewDelegate protocol which allows some greater control. Like what rows you can select, or some extra configuring of a custom tableview cell.
I must say that back in the day when I started developing desktop applications ( only had experience with web technologies ) that this design pattern confused me as well. Hope you will get your mind round it soon.

create a new object

I want to create a new object so as to instantiate and use it several times;
For example, if I want to create an object that has a label and a button inside, how do I? I created a new NSObject but inside it has nothing, then how do I make everything from scratch since there was a viewDidLoad for example (obviously, since it has a view)?
thanks!
Your questions lead me to think that you're really just starting out. There's nothing wrong with that, but rather than trying to summarize several megabytes of documentation in a few paragraphs, I'm just going to point you to the iOS Starting Point. I think that you're just trying to create a container that can hold other UI components? If so, use a UIView for that. However, don't jump in and try to get something specific done without first reading through some of the Getting Started documents -- you'll just end up back here, and we'll just point you back to the docs. You might like the Your First iOS Application guide, as that lets you get your feet wet but explains things along the way.

NSTableView, multiple cells and bindings

I'm trying to create a view that's similar to Motion's properties views.
Each of my property objects contains a definition of the kind of cell it wants to display as. But at the same time, I'd like to use bindings so that values are automatically updated as they can be changed elsewhere.
I've tried a few different approaches to the problem.
Multiple cells and dataCellForTableColumn: while this allows rendering to happen properly for all cell types, I lose bindings.
NSProxy: I've also tried using a proxy object that I thought would forward all methods to the selected cell type behind it, but again, bindings don't seem to work here.
Has anybody had any experience with this kind of problem before? Or is this one of the cases where bindings isn't going to cut it, and I'll need to do the heavy lifting myself?
Cheers!
I haven't actually tested it, but you shouldn't be losing bindings when you use dataCellForTableColumn:row: ? Can you describe in a bit more detail what you've tried with respect to bindings?
You should be able to set the column's value binding to the "value" property of your object. Then if you return the correct type of cell in dataCellForTableColumn:row: it should display correctly.
Edit: --- deleted gratuitous incorrect advice about cells vs views :)