How to add an image next to picker view entries? - ios

As illustrated in this picture, I need to add an image next to my picker view entries, it's a picker view that is added to a UITextfield, what is needed is adding an image in place of the blue triangle, an image next to each option, how to do this?
I found solutions for this in objective-C, but found nothing for swift.
I will pick the first answer as the answer for this question and vote up for any useful comment..
Thanks.

With a picker view you either provide a title for each item, or a custom view for each item. If you want an image combined with text you should provide a custom view.
You need to implement the pickerView:viewForRow:forComponent:reusingView: method in your picker's data source. You'll need to provide a view that contains an image view and a label. You can either create that in code or load a new one from an XIB file each time you need to create one. I don't have any ready-made code for you, but this isn't that difficult.

Related

UIImageView Not Deleting From UITableView

I have created a UITableView with a cell inside. Inside this cell view, we have a Content View, and in that, I have subtitle text. This is all in the storyboard. I wanted to have an image right next to the cell, so I put an image and chose a picture.
The image turned out really small, and I couldn't even make it bigger - it was that small. So I put another image view that I created in the view and plopped it into the tableView. Then I try to delete the first tiny image view. It doesn't delete.
When I try to move it out of the Content View, it duplicates itself. When I try to drag it to the view and out of the Content View, it sends a duplicate version. So I tried to change the cell type from subtitle to custom, hoping that everything in the Content View would disappear and I can put it in again.
Then, Xcode crashed. I tried again with changing it to custom, but it crashed again. I didn't put the crash report because it is very long but tell me in the comments if I should put it, and I will edit this question to put it in. Tell me if there is any other information you need.
Thank you in advance!
UPDATE:
I deleted the whole cell. I realized that when putting a picture in the attributes inspector of the table view cell, it makes the picture either really big or really small. It doesn't allow me to resize the picture or move the picture without randomly duplicating it. Does someone know why this happens?
If you want to customise the size of your image, you can do so very easily by creating a UINIB file and then customising the look of your cell in the new file created. You can do so by creating a new cocoa touch class of type UITableViewCell and then select the create XIB file checkbox. Then you will see a similar to main.storyboard layout which works exactly like the main.storyboard and the difference is that it is specifically for the table cell. Make sure you register the UINIB with the table view so that you can control the data that shows up in your cell. I hope this helped!

How to structure different components within cell, rows and sections?

I am trying to understand how to structure different components within rows and sections. So my question are
1.would the top view,imageview and the components under it be separate cell or a single cell within a section.
2.What if one section does not have a imageview or a certain component. Would we just hide that view or would it be in a separate cell and that wont be called. And if hiding is the solution, how would you remove the space.
I am looking for just an abstract answer nothing specific. Just to understand how to structure views in tableviews
You pull all in one cell. For hiding any view (image, button, etc),
Put top content, image and comments on stack view.
Whenever there is no image, use imageView.hidden = true
Image space should automatically disappear.
Refer to this link for more elaborate tutorial
It depends on the preference of the developer. If you want a more flexible and easy to update/adjust view you can create a separate cell/nib file for that view. Additionally you can create it on one cell only but be careful because updating of design/view/content won't be easy.
If the imageview does not have a value I suggest that you always put a placeholder for that imageview so that the user will know that the image is not fetched.

Show typeahead popover while user is typing

I'm trying to do something like the following:
As you can see, a popover shows up as you start typing, and updates the results as you type. My question is regarding the UI and how to actually implement it.
How can I show a custom popover when the user starts typing? Is it possible to load a custom view into a popover? Additionally, what would I need to do if I wanted to also include an image view in each typeahead result?
Good question, which most beginners have. Follow my instructions given below.
First create a view controller and design it as you wanted it to be and include a Search Controller and implement it's delegate functions in the view controller.swift file(Hope you know to work with delegates for controllers,else just google it...It's pretty easy).
Then add a Tableview in center of the view for viewing the results like shown in your question & and add a custom cell into the table view and then setup a custom class file for that cell exactly like how you works with tableview controller.Use just the basics of tableview stuffs.
Setup outlets and all for the controls and buttons.
Create an array named 'filteredResults' or name it as you like to reload the tableview data whenever the text is changed in search bar.
To detect and call your function while user changes text in search bar,You can use didTextChanged delegate function of search bar.
Note though that it's better to find everything else by your own so that you feel confident about yourself when you solve the problem at the end.

Want to achieve this kind of functionality in iphone app

I am having an app in which I want my view to be loaded like shown in the screen shot below.
The following view contains page control to show multiple images,buttons,labels,resizable text view and resizable text field in a single cell of table view.
There will be number of rows in a table view and rows will be generated dynamically.
Is there any cocoa control or tool which can give me functionality like this?
I have searched on cocoa control and goggled it a lot but couldn't find any matches to achieve this.
I thought of taking different views with sub viewing it didn't get much idea of how to generate it dynamically.
Please help me if someone has achieved this kind of functionality in any of their projects.
Thanks in advance.
Hint :
Divide each items in cells for single section, that means, one section for one item.
for e.g.
User photo, User name, User location and Post time in one cell.
Image gallery in another cell with page control on it.
Favourite (liked) post, comment on post and price in individual cells.
what you've to do is, create and add each item in a cell. While you're giving the height of each cell using delegate, check for conditions for which you're assigning the height. For e.g. if you've likes for the post (favourite) then only give height for that cell otherwise pass 0 (zero). Do the same for everything or as per your requirement.
For comments, you've to calculate text height, and based on that, you'll need to set height for comment cell.
References:
Here's a nice tutorial for this (not exactly) stuff. Rebuilding Instagram Feed Table View. I also googled a lot and found this, https://www.cocoacontrols.com/controls/stxdynamictableview, you may also need https://www.cocoacontrols.com/controls/mhpagingscrollview for showing image gallery.
P.S. This is not a "lunch plate" of course you've to make it for your self. Get hands on the keyboard! :)
Good luck!

how to connect textfield with table view of listed options instead of keypad

I need to be able to disable the keypad in a textfield, and instead when the user taps on it to start editing, a new table view will appear presenting a list of possible strings with which the textfield should be filled.
Anyone has any suggestions on how to achieve this?
Thanks in advance
p.s. I tried already but this functionality cannot be nicely implemented with a picker in my case, as there are too many options to choose from and (more importantly) each one of them is a rather long string and cannot appear entirely in a picker.
I believe you just need a regular cell that, when tapped, pushes a new detail UITableViewController with all the options to choose from. Once an option is chosen, set the cell's textLabel to whatever option have been selected.
If you'd like to go for an easier path, then you should also probably check the free Sensible TableView framework, as it has these kinds of cells out of the box (called selection cells). You just pass on your strings array to the selection cell and it will automatically display the detail view, and even assign the selected option to one of your object's properties if you wish. Should save you some good amount of manual work. Good luck!

Resources