I am trying to implement Tim Keating's answer from here: Loading a Reusable UITableViewCell from a Nib
I made a view XIB and assigned the view's Class to UITableViewCell.
When I go to the Attributes Inspector though, all I see are the "Simulated User Interface Elements" and "View" sections. I do not see a "Table View Cell" section like in his answer :( I tried closing and reloading, it still won't show.
You can always select an empty XIB and pick a UITableViewCell element from the object library.
Related
I have a view like this
Basically it is lots of static tableview cells , where each cell has horizontal scroll views and stack views. Now trying this in storyboard has slowed down it completely, where adding or deleting a constraint or just changing label text in Xcode 9 takes more than 30 seconds and there is always a spinning beachball.
What are the ways I can reduce system overload or make storyboard a bit faster.
Or is it better to move to laying out views in code. In that case any help / advice in this regard will be highly welcome.
Thanks in advance for your efforts.
Here is the link to GitHub repo for the same
You should use a few prototype cells, instead of repeating static cells that are virtually identical. You have at most 6 unique types of cells here. For example, Inputs A, D, E are the same. Inputs B, C, F are the same.
It's beyond the scope of the question to explain how to do this in detail, but the basic procedure is as follows.
Let's say you want to add a prototype cell that you can use for Inputs B, C and F. This is your most basic input cell that will have one text field.
Add to your project a new class that inherits from UITableViewCell.
Name it something like BasicInputCell.
Open your storyboard, select your table view and open the Attributes inspector. Increment the Prototype Cells setting by 1. Xcode will add a prototype cell to your table view in the storyboard
Select the prototype cell and open the Identity inspector. Set the Class name to the name of your cell, BasicInputCell.
Open the Attributes inspector and set the Identifier to the same value so that you can dequeue it by this name.
Add a text field to the cell in the storyboard. Open the Assistant Editor and Control drag from the text field to your class to create an IBOutlet.
Repeat for as many unique cell types as you need. Customize each cell type with different controls on it, such as date picker, as needed.
In your table view controller, dequeue the cells of the type you need based on the index path.
I am developing an iOS application that will act as a kind of email client.
One of the views in my story board is an inbox in which I would like to display for each email:
The sender of the message, the title of the conversation, the begining of the message body and the date & time at which the message was sent.
I have used a UITableViewController to display the list of emails and the UITableViewCellStyleSubtitle as the table's cell style (this allows me to set cell.textLabel.text and cell.detailTextLabel.text).
Is there a way to display more than 2 labels in such a table?
Many thanks.
Create a UITableViewCell subclass, using File > New > File and select Objective-C class. Set the class to be UITableViewCell.
Now create a xib file, using File > New > File and under User Interface, select View, name it the same as your subclass you have just created.
In Interface Builder, delete the temporary View and drag in a UITableViewCell from the Views on the right. Click it, and under the identity inspector, change it's 'Custom Class' to be the UITableViewCell subclass you created.
Now create your labels, and their respective IBOutlets in the class you created. Then all you need to do is register your class with the UITableView:
[self.tableView registerClass:[YourSubClass class] forCellReuseIdentifier:#"Cell"];
And in tableView:cellForRowAtIndexPath:, return your custom cell and set the labels.
A simple Google search finds the answer and detailed tutorial:
http://code.tutsplus.com/tutorials/ios-sdk-crafting-custom-uitableview-cells--mobile-15702
If you are using storyboards, use the prototype cells with the same explanation of Jeffs answer. It would be more easy.
I created an xcode project with the master detail template. I want to customize the cell to put my data into 2 separate labels. I tried customizing the cell in the storyboard editor, but it seems like all of the stuff on the cell is locked in place. I am fine either creating the custom cell programmatically or in the storyboard editor. I know I could just set the text on the default textLabel to blank and then create the other labels programmatically, but that doesn't seem very need to just have a random empty textLabel in the middle of every cell. So I am wondering if there is a way to edit the cell in storyboard editor, delete the default textLabel, or resize and reposition the textLabel to where I need it to go.
Any help is greatly appreciated.
Thanks in advance.
That's standard practice. Just ignore the built in textLabel and be done with it. By default the label is blank anyway. It's set in code.
To access new labels and such, create a new custom class for the custom cell (File|New|File...|Objective-C Class in XCode), give it a name and for the subclass choose UITableViewCell. Finally, on the Identity Inspector for the custom cell in Interface Builder, choose that new class for the Custom Class.
Now, from the Assistant Editor in XCode, you can CTRL-drag new labels and such to the .h file of the new custom cell class to create IBOutlet properties.
Be sure to set the cell Identifier on the Attributes Inspector tab for the cell and reference that in your code, especially in cellForRowAtIndexPath.
Import the custom cell class's .h file in the view controller's .h file, then cast the cell to your custom cell class in cellForRowAtIndexPath to access the new properties or change the definition UITableViewCell *cell = to your new class like MyTableViewCell *cell =.
By default, the Style of the table cell is "Basic" in Master-Detail projects. Select the Table View Cell and open the Attributes Inspector. Change the Style from Basic to Custom.
Doing this removes the default label and allows you to add new controls.
So I guess the table view has been designed around the idea of using dynamic data received at run time, but I want to make a settings type app where all of the cell values are known as I build it, so I was hoping to be able to set the section / row configuration, labels ect, as well as the properties for each cell (whether it has other views inside it like a switch, or whether it is a button etc) all in interface builder.
can I do that? how?
I am using xcode 4.4.1
To use static cell content you have to make sure that you are adding a UITableViewController not just a UITableView dragged into a UIViewController. The latter requires dynamic prototypes.
Once you've added the table view controller to your storyboard it is as simple as selecting "static cells" in the attributes inspector. From there you can drag and drop UITableViewCells and modify them as you wish.
I have added prototype cell in one of the controllers that is part of the storyboard I'm designing. It has various labels, buttons, bells and whistles.
But how do I know create outlets to that cell's elements? If I click the assistant in Xcode, it will show me the dummy source of my inherited UITableViewController and not of the "DetailsCell" which inherits from UITableViewCell and is specified in the custom class input field in IB.
I could of course use ViewWithTag() but I'd rather have something strong typed.
With any object you can create with IB, you can assign it to a different class (one that you wrote). This is not different for cells. In the same way you can make IB instantiate MyFooView instead of UIView (MyFooView being derived from UIView), you can do the same for the cells.
Click your cell, click the 3rd icon on the shelf to the right. You will see a section called "Custom Class" and a text field called Class. Select the new class you've just created that is derived from UITableViewCell (let's call it MyCell). You can add IBOutlets to the MyCell class.
You first need to create a class DetailedCell and add IBOutlets to that class.
Then in the Storyboard/IB, assign that class to the prototype cell and those outlets will be available to fill.