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.
Related
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.
I've been searching and can't find an answer anywhere. I want to a create a really simple grouped table view for "settings" of my app. User taps a button and I want to load a UITableView that has 3 or 4 cells in categories. Is there a way to just set one up in IB without the dynamic code building (ie. cellForRowAtIndexPath).
Note: Most answers I have found pertain to storyboard, which I am not using.
No, you can't. tableView:cellForRowAtIndexPath: is the way a table gets its data -- there's no way to populate a table without that in iOS (in OSX you can use bindings, but they're not available in iOS).
If you only need a few cells, are you sure you need to use a table?
I am relatively new to Objective C/iOS development so I realize that this may seem like a basic question: For iOS 5+, I'm looking for a primer on how to create a tableview that has cells with a variety of data. For example, in my data array I might have data like:
Restaurant Name (basic string)
Restaurant Logo (string name of an image file)
Restaurant Rating (an integer)
In a single cell, I want to display the logo of the restaurant, then the name, and then show a number of stars based on the rating integer (ie a "4" would display a single star image 4 times).
I can't tell if I can do this with the standard table cell or if I need to create a custom table cell object.
Help!
Here is a good place to start.
http://cocoawithlove.com/2009/04/easy-custom-uitableview-drawing.html
One point they make is that if you subclass UITableViewCell then you have done something wrong. Instead, read it as most of the time customizing the standard UITableViewCell is sufficient.
For spectacular customization then deriving a class from UITableViewCell is fine.
I'll try to give you some suggestions on how to reach your goal based on my experience.
I think you can use both a default cell or a custom one.
In the first case, you have can use a simple cell (UITableViewCell) with a default style.
The properties you can use are: imageView for the logo, textLabel for the name and accessoryView for the rating.
Take a look to A Closer Look at Table-View Cells for info about table cell structure.
If you have to maintain a specific order for your cell content you need to create a custom cell that extends UITableViewCell and override layoutSubviews methods. I've already answered a question in this stackoverflow topic custom-uitableviewcell-with-an-optional-image.
In the second case you can use a custom xib or a completely fresh cell and do the stuff there. Out of there you can find lot of guides to do that. Here fews:
The one that #bbarnhart has written
custom-uitableviewcell
creating-a-custom-uitableviewcell-in-ios-4 (suggested)
P.S. For creating a rate view I suggest to take a look at how-to-make-a-custom-uiview-a-5-star-rating-view.
Hope it helps.
You can do this using a standard table view cell with an image and subtitle. The main text label is the restauraunt name, the image view holds your logo, and the subtitle can be made of the appropriate number of unicode star characters (for example, #"\u2605").
Does anyone have any info on this? I'm new to cocoa, all tutorials seem to be for iPhone which uses a different view controller. Anyone willing to provide a step by step for adding labels to a custom cell? (I'm pulling from Core Data)
EDIT: It's important to note I'm using Core Data here. Many tutorials use arrays.. I don't understand why you would use that??
I'll award an answer quickly!
Zach
I'm not sure if this is going to help you, but your problem seems unrelated to your use of CoreData.
If I've understood your problem correctly, here are some steps:
Populate your NSTableView
Using CoreData, what you can do is put an NSArrayController object in your XIB document, set its mode to Entity and choose the Entity you want to display in your TableView (all of this from the first tab of the inspector on your array controller object).
Then, bind your NSTableView Content to the arrangedObjects of the array controller. You might also bind the selectionIndexes and use some sort descriptors on the array controller to order your data, as CoreData will give you a set rather than an array.
Click on your table view as many times as necessary as to select the table column in which you want your custom cell to appear, and set its Value binding to arrangedObjects too.
Set your custom cell
Finally, click on the cell of this table column and in the "Identity" of the inspector, change the class name of the cell to the class name of your custom cell.
I'll let you read the appropriate documentation to implement your custom cell according to what you want to achieve.
With the different bindings I've described, the objectValue of your cell should be the object from your array controller at the same index of the row your cell will appear on.
Please note that I've not tested again all of these steps but answered from memory... there might be details I've missed but you should have the main steps here.
Im using a navigation controller and a normal view. In the view I'd like a UIPickerView with custom values in it. It would have one column with about 15 values in it. And I want the ability to add an action to each value.
Is there any way I can do this using Xcode? I can't seem to find the corrent help.
Cheers.
You need to look at the documentation for UIPickerViewDelegate.
In order to have an action for each value you will implement pickerView:didSelectRow:inComponent: and have a different action based on which row was selected.
For the contents of the rows you can implement pickerView:titleForRow:forComponent: if your contents are simple text.
If you want custom drawn contents you can provide a custom view for each row with the pickerView:viewForRow:forComponent:reusingView: method.
See the UICatalog example that is available in the iPhone Developer examples.