How to edit a table view cell's text in Interface Builder? - ios

I am trying to design a settings screen. I added a table vc in my storyboard and changed it to static cells. Then I configured the number of sections and the number of cells in each section.
Now I want to add text to each of the table view cells. I tried to select the cell and edit the text property in the property inspector. But I could not find a text property. I then tried to drag a label to the cells' content views. But I can't put the label in exactly the same place as the others. Also this method is very tedious.
I mean there is even a property called textLabel in UITableViewCell class! How can there not be a corresponding property in the interface builder?
How can I do this in IB? Must I use code to set the text of each cell?

Make sure you selected Style: Basic at the Cell's Attribute inspector, and then select the label.
Also, because of the cell has a contentView, the easiest way is to find it in the view hierarchy, or click on the cell until you see the inspector of the label

Related

Text not appearing in tableview controller

I have a tableview controller as my initial view. I added some text into it and it's not appearing. First i added some labels, and none of them was appearing, i thought maybe it was a constraint problem. So i added constraints and still didn't work. Then I made the cells basic rather then custom. In basic, it gives you text for you. And still the text isn't appearing. How can i fix this?
Note: This is a new project, I have tested this on a real device and have the same issue.
The table is created with the default prototypes of cells (Content field is Dynamics Prototypes) that need to create and add from the code. If you want to make a static cell, you need to do this in storyboard:
Select TableView
Set Content field in Attributes Inspector to Static Cells
Add your labels to Static cells

UITableView cells with Text Fields and other controls

In Xamarin, I want to be able to create a UITableView with the cells to have Text Fields and other controls possibly. How can this be done through the Xcode Interface Builder (or though the Xamarin iOS Designer)?
I would like it to look something like this:
Can someone walk me through doing this?
Bill
This can be achieved through Xcode Interface Builder as follows:
Add UITableView to your view
Type UITableViewCell in the Object Library and drag & drop a "Table View Cell" item to the "Table View" in the View Controller Scene, so that "Table View Cell" is added as a subview for the UITableView. As result, the "Table View Cell" item appears in the storyboard in the table view under the "Prototype Cells" section.
Add any UI elements (labels, text fields, buttons, etc) as subviews for the Table View Cell's Content View.
To have several different cells types, create several prototype cells (i.e. drag & drop one more UITableViewCell onto "Table View").
To distinguish different types of cell prototypes, please enter cell identifiers into Table View Cell's attributes pane.
Set up outlets (UITableView's delegate & data source, outlets for cells' content view's subviews, etc) and actions.
I've attached an Interface Builder's screenshot demonstrating 2 types of cells added to a table view (one with a label and a text field, another with a label and a button).
direct link to a larger image

How to change Tableview's custom cell width dynamically ?

I have a table view and its every cell`s width say 1024px , so my requirement is after clicking a cell tableview's width will change logically. And my table view is bit complex.
Every cell contains a custom view which is defined in another class. Please help me..
I do not believe there is a way to modify a single cell's width without changing the width of the table view, only height using tableView:heightForRowAtIndexPath:.
Therefore, you might want to change the width of the custom view inside your cell.
First, to get the cell in question, call cellForRowAtIndexPath: on your table view wherever you need (if you want to change the width on tap, that would probably be in your tableView:didSelectRowAtIndexPath:).
To access your custom view, you may give your custom view a tag number inside of the UITableViewCell by setting the custom view's tag property when creating the cell or in the storyboard. Then, call viewWithTag: on the UITableViewCell instance to get the custom view, and modify the width of its frame property.
Another, perhaps more suitable option would be to use a custom UITableViewCell class for your table view cells. That would mean subclassing UITableViewCell and creating a property for your custom view, which would allow you to access the custom subview through the getter and then change its frame property.
If you need the width of the custom view's container to change (which is currently your cell), simply embed the custom view inside a UIView and modify the UIView's width rather than the UITableViewCell's instance in the same manner described above.

iOS- How do I make each cell in a table view bigger?

This might be a noob question,but how do I make each cell in a UItableview bigger through interface builder?
Select the table view in your nib or storyboard. Then show the Size Inspector. (You can do this by choosing View > Utilities > Show Size Inspector… from the menu bar, among other ways.) The first section of the Size Inspector is the Table View Size, and the first field in the Table View Size section is the Row Height.
Changing the Row Height field in the nib has the same effect as setting the rowHeight property of the table view instance at runtime.
If you want rows to be different heights, you must either implement tableView:heightForRowAtIndexPath: in your table view's delegate, or use a storyboard with static cells.
Assuming you have set the dataSource and delegate to self, this should work:
- (CGFloat)tableView:(UITableView *)tableView heightForCellAtIndex:(NSIndexPath *)path
{
return 50.0f; //Replace with how high you want.
}
Typed on mobile, test before shipping.
Yes, it's code, but it's a whole lot easier than anything else. Easier to change, too.
Select the Table View Cell, then choose the ruler icon on the right panel, check Custom next to Row Hight, then just change the row height.
To change the width select the view controller, find Simulated Metrics in the tab to the left of the ruler, change Size to Freeform, then select the Table View, go back to the ruler tab and you should be able to change the width which the cell will adjust to if Autoresize Subviews is checked (which it is by default).

Static table view cell's height in xib not being applied

I have created a static table cell in a .xib, however when it is displayed the cell height set in the xib is not being applied, instead the cell is being displayed with what looks like the default height for cells.
I have set things up as:
1) The table view controller derives from UITableViewController
2) The TVC is not contained within a xib and is created in code in the app delegate and added to a tab bar controller.
3) The TVC is created using initWithNibName:bundle: with the nib name supplied as the name of the xib containing the table view and the static table cell.
4) The TVC has an IBOutlet iVar of type UITableViewCell*
5) cellForRowAtIndexPath returns this iVar.
6) numberOfRowsInSection returns 1, numberOfSectionsInTableView returns 1;
7) The xib contains a table view, which is connected to the File's Owner's view. The File's Owner is set to my custom table view controller class.
8) The UITableViewCell in the xib is connected to the outlet of type UITableViewCell in the File's Owner.
9) THe Table view style in the xib is set to grouped.
10) The size of the Table View Cell shown in the size inspector is N, and this is where the problem is. If I change N manually or by resizing the cell visual representation then this size is not applied when the table is drawn. I have also tried setting the view Frame Rectangle height in the size inspector to match.
It doesn't matter what value N is, big or small.
11) The cell's height is not being set anywhere in the TVC, if I do set it using self.tableView.rowHeight then its height does change. But I do not want to set it explicitly like this, I want the height size in the xib to be picked up.
This has been driving me nuts for a few days, and reading several tutorials on table views (including Apple's table view programming guide, especially the section on static cells, whose instructions I followed in the first place to set everything up) has not given me any clues where the problem lies.
TIA
Implement heightForRowAtIndexPath and return the height of the UITableViewCell linked to in your IBOutlet.
Do you have - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath defined in your UITableView delegate?
You may want something like:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 30;
}
Try this post if you're still having trouble try this post: Setting custom UITableViewCells height
I had the same problem and everyone here and on other threads suggests writing code to fix the problem, which seemed wrong. What's the point of using IB if you have to write code to get the properties right?
The answer turns out to be very simple but took a bit to track down. In IB there are two places that row height can be set (just like there are two places to set it in code). One is on the table, the other is on the cell.
The place I was (incorrectly) setting it was the tableViewCell's "Row Height" property in the Property Inspector. Changing this value had no effect on row height at runtime.
Then I found and set the "Row Height" property of the TableView (one step up the object hierarchy) and viola, the row height is correct at runtime. Once this was working I turned off the override of Row Height on the TableViewCell (uncheck "Custom" on the Row Height property). I was afraid this might be evaluated on each cell, which would kill performance since all my cells are the same height.

Resources