Is there a standard way to set up a table to allow editing-in-place, kind of like this:
I only need editable text at the moment, but I might need UISwitches or UISliders in the future.
Yep. Just add a UITextField, with its font and textColor set to appropriate values, as subviews of the table cell's contentView. You probably want to give the field a tag as well, so that you can easily grab a reference to it using the contentView's -viewWithTag: method.
With short forms you can get away with keeping an array of cells, one for each field, and handing them off to the table view without going through the -dequeueReusableCellWithIdentifier: mechanism, but if you've got a lot of stuff to enter then it gets more complicated. In that case, you probably want to assign a different reuse identifier to each type of cell—one for text-field cells, one for switch cells, one for slider cells, etc. Once you've dequeued or created the row's cell, you'd then grab its control from the content view (as above) and set its value from wherever you've stored that.
Edit in-place using a "Content: Static Cells" and make it look like a default styled UITableviewCell.
In UITableView create two cells: one Custom and one Subtitle Styled.
Copy the "title" label corresponding to the Subtitle styled UITableViewCell to the Custom UITableViewCell.
In Custom UITableViewCell, drop a UITextField. Copy in this the style parameters from the Detail UILabel from Subtitle Styled UITableViewCell in this UITextField.
Do the necessary arrangements.
The looks pretty equal, aren't they?
Now, do the IBoutlet stuff.
Related
I am new to iPhone development and I am looking at exactly what is shown in the picture to allow users to write input.
But I cannot find what exactly is it! Are those some special kind of UITextFields? Are they a special kind of UITableView? What is it?
This is a UITableView with custom UITableViewCell's that contain UITextFields. You can easily do this by loading your UITableViewCell from custom XIB files, in which you've dropped UITextFields. As far as the "hints" you see in each field, that's the "Placeholder" property of UITextField.
Those are grouped tableviews with custom table cells that contain textfields and single line etched separators. Make sure to set the style to "grouped"
The above basically consist of UItableviewCell with a Uitextfield within it.
If you are on ios5 (which i assume you will be), you can add UItableviewcontroller from you Interface Builder and from there, taking the advice to set the style of the table to "grouped".
you should have the similar outlook of the above for the background.
In here, if you select a cell you should have the option to set a few different style to your uitableview cell.
If none of the default styles works for you, just select custom and add your own uitextfield or uibutton.
Note: There's a bit of difference between prototype cell.
I´m new trying to make some apps using objective c, so I´ve an idea using uitableview but I don't imagine how can I get this.
I´m trying to do something like you do in a spreadsheet where you have a fixed header and the first column too
So when scroll the uitableview vertically the header will stay visible at top of the table and rows will change
And finally when you scroll in horizontal direction the first cell of the row will stay visible and will change the header depending of how you scroll the uitableview
I hope you could give me an idea how to get this, because I don't imagine how to do this, also I don´t have a lot of experience with this programming language.
Thanks!
In a non-grouped table, section headers "stick" at the top of the table as the table scrolls. You can provide a custom UIView (or sub-class thereof) for a section header through the delegate method –tableView:viewForHeaderInSection:. This header view could be created on-the-fly programmatically or loaded from a NIB file. Either way, you can have it contain whatever you want, even update it as the app runs (provided you have given yourself access through ivars or class variables to the views contained in your header view.) If you go this route, you'll want to be clever about allocating resources that comprise this view, so that you are not constantly allocating new resources! This delegate method can be called frequently, and on all but the first call you could simply return the previously created (but updated as and if necessary) header view.
UITableView isn't designed to do this, although I am sure you could figure out some way eventually.
My approach would be to use a fixed UIView of some sort (possibly a UILabel, etc) in a UIViewController's nib as the header/locked cell, and add the UITableView under that. You couldn't then use a UITableViewController, but would have to implement the delegate and dataSource methods in your UIViewController, and use a UISwipeGestureRecognizer to pick up the gestures from the tableView and update the other views.
I've done this by adding a UIView that mimics the first cell in my table. In my case I am using a subclass of UITableViewCell, but that is perhaps not relevant. Normally this view is hidden with an alpha of 0.
If you view controller is the delegate of the UITableView then it will also be the delegate for the inherited UIScrollView. So in your view controller you can implement scrollViewDidScroll. When the scrollView's contentOffset is positive I set my custom view's alpha to 1 (I also do some small size tweaks to make sure there is a perfect match), and when the contentOffset returns to 0 or negative, I reset the alpha back to 0.
prepend the first row of data in your array to what ever in the first row is your headings, put the text in bold with attributed text, It wont be sticky but you will have headings...
Look this pic:
The usernames are UIButton. How can I put a UILabel (with the comment text) just after the UIButton (with the username) ?
The UIButton username's is dynamic. How can I do this?
That looks like a UITableView, if that's the case you should subclass UITableViewCell. If it isn't, I would
consider making it one
build a container class that (or make your subclassed UITableViewCell such that it) contains both a UIButton and a UILabel and dynamically position the text inside the label according to the size of the button (for instance, adding the right number of spaces to the beginning of the text).
You're going to have to use Core Text or web views to achieve this. There's really not a super easy way to do this. It's simple enough to place view next to each other based on their calculated sizes, but to have text wrap to multiple lines with embedded font style variations and attachments (i.e., images), you're going to have to read up on Core Text or use XHTML in web views.
I have a complex settings style table where individual cells represent different aspects of a data model class. Users can click into a cell and edit individual attributes, such as say if I have a user class, a name, date of birth, etc. My question is, do I need to have an instance of UITextField for each unique cell? Can I just create one subclass of UITableViewCell, set up a delegate, and determine where it is from there?
What's the best approach?
I would recommend creating a subclass of a UITableViewCell. You could do this either purely programaticaly, or if you have an aversion to CGRect's (or want to be able to drag and drop your layout around) with a combination of a XIB and a custom class file.
The Subclass would then contain the UITextFiled's you need, and can also have a delegate or datasource that you can use to point it to your data model object.
It's better to have the UITableViewController you are using act as the text view delegate for each cell - make sure you are re-using cells and when you create them or reuse them attach your class as the delegate for the UITextViews you have via a custom UITableViewCell class with accessors to get to the UITextViews.
If you set cell classes as text delegates you may run into issues if the user scrolls a table view cell off screen with the keyboard up.
Depending on the result of a condition, I want to display a UIImageView in a table cell. Otherwise display UITableViewCellAccessoryCheckmark. I'd like to construct the cell in IB. The part I'm not sure of what to do with the UIImageView when I don't want it displayed. If I were constructing it all programmatically, I'd add the UIImageView as needed. But since it will be done in IB, the UIImageView is always there. Should the default be leave the cell alone (image displays), otherwise remove UIImageView and display UITableViewCellAccessoryCheckmark? If that is done, will I need a tag on UIImageView so it can be accessed and removed?
You can easily control the visibility of any control, including UIImageView. If you'd like to build things in IB then one solution is to add the controls you need, expose them as properties, and then hide the ones you don't want for a given cell.
E.g.
cell.image.hidden = YES;
When hidden they have no draw-overhead, and although your cell may have thousands of rows there will be very few actual cells, so it's a fairly efficient solution. Just remember that cells are reused if you call [tableView dequeueReusableCellWithIdentifier] (which you should do) so you'll have to explicitly show/hide control whose visibility may have been changed.
An alternative is to have cells with and without images and choose the correct one when adding data to your table. For cells that are similar managing two similar-yet-minorly-different assets would probably be a pain though.