Change textlabel in static cells in UITableView

I have a static UITableView, content of each cell I've made in storyboard, but I need to change texLabels of some cells programmatically while runtime. How can I do it?

Create a property for each cell you want to change in your table view controller, like so:

@property (weak) IBOutlet UITableViewCell *cell1;
@property (weak) IBOutlet UITableViewCell *cell2;

Connect each one to a cell in Interface Builder.

When you only need to change the label's text, you can use

self.cell1.textLabel.text = @"New Text";

If you need to replace the whole label, use

UILabel *newLabel = [[UILabel alloc] init];
self.cell2.textLabel = newLabel;

Modifying the text in a static UITableView cell?, Table View (static cells) - Table View Section - Table View Cell - UILabel (with the text property you want to modify). Declare an IBOutlet  Custom cells for static table view are done in the exact same way as custom cells for dynamic table views. One needs to register the nib and then use the cellForRowAt method to use the custom cell. The biggest difference when using a static table view is that you need to do it through Interface builder , and it needs to use a UITableViewController .

@RossPenman has posted a good answer.

@ggrana noted a potential issue to do with memory and cell reuse, however don't worry about that ...

For a UITableView with Static cells all the cells are instantiated up front, before viewDidLoad is called on your UITableViewController and aren't reused in the way that dynamic cells are. As such you can even just take IBOutlets directly to the UITextFields, UISwitches, UILabels and things you are really interested in that you have dropped into you static cells in the Storyboard.

Configuring the Cells for Your Table, In your tableView(_:cellForRowAt:) method, configure the content of your cell using the textLabel , detailTextLabel , and imageView properties of UITableViewCell . Static views such as labels and images make the best content for cells. If the row heights are not all the same, or can change dynamically, provide the  To configure a prototype cell with one of the standard styles, select the cell in your storyboard and set the cell's Style property to a value other than custom. In your table View(_: cell For Row At:) method, configure the content of your cell using the text Label , detail Text Label , and image View properties of UITable View Cell .

I needed this.

dispatch_async(dispatch_get_main_queue(), ^{
    (...textLabel updates)
    [self.tableView reloadData];

Multiline UILabel within a Static UITableViewCe |Apple Developer , I am trying to make a UILabel within a static UITableViewCell multiline depending on its content, which changes. And then I am attempting to calculate the height that the row must be in order to accomodate the multiline  This will make the cells grow to accommodate the larger text size. We’re done! Static UITableView. Things are more complicated for static tableViews. Just setting the cell style to ‘Basic’ or ‘Right Detail’ will (in Xcode 7 and Xcode 8 beta 6) lead to the disappearance of the textLabels when changing the text size.

You can get the cell from your table view using the method cellForRowAtIndexPath, you will need to define a outlet that retrieves your tableview.

__weak IBOutlet UITableView *tableView;

after that you can get the cell like that:

NSIndexPath* indexPath = [NSIndexPath indexPathForRow:yourRow inSection:yourSection];
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
[[cell textLabel] setText:@"Your new text"];

Maybe after setting the text you will need to adjust your label, or your cell height, if you want a deeper help provide more information, and I will be glad to help you.

And you are done, hope it helps.

Handling Dynamic Type Changes in a Static UITableView, Static UITableViews show a blank cell when adjusting for Dynamic set your UILabel to automatically adjust the font size to type changes. Once changed, you’ll have a table view with three empty static cells. Set the Content Property to Static Cells To get the desired view of the Settings screen, change the table style from “Plain” to “Grouped” in the Attributes inspector of the table view.

Swift 3 solution:

First make a IBOutlet of static TableViewCell

@IBOutlet weak var cellFirst: UITableViewCell!

then in viewDidLoad change label Name.

cellFirst.textLabel?.text = "Language"

Note: If you have attached a label on TableViewCell then just hide it using storyboard.

Automatically resizing UITableViewCells with Dynamic Type and , Automatically resizing UITableViewCells with Dynamic Type and NSAttributedString Replace it with a new Table View Controller, check its “Is Initial View  Any screens in my app that used a static UITableView were not resizing to account for the larger label size inside the cells. Instead, the cells would be blank. Instead, the cells would be blank. The problem occurred when the user changed the Dynamic Type setting while my app was still running.

Static Tables and Dynamic Type, You should also be able to make the static cells self-size by setting the row height in the device settings the size of the static table view cells will need to change. UITableViewCell { @IBOutlet weak var titleText: UILabel! }. [Swift] How to make a UITableView static cell segue to a ViewController within a Tab Bar View 1517 Views 8 Replies Latest reply on Sep 30, 2018 1:38 AM by Claude31

UITableViewController - iOS & Swift Tutorial, Use Edit » Delete ⌘⌫ to remove the existing controller from the storyboard. In the Attributes Inspector configure Static Cells for Content to textLabel?.text = "​Section \(indexPath.section) Row \(indexPath.row)" return cell }. I want to change cell text color and show image fill with blue color on click UITableView cell in xmarin.ios. This site uses cookies for analytics, personalized content and ads. By continuing to browse this site, you agree to this use.

Using Custom cells to customize UITableViewCells, This tutorial shows you how to use the cell style Custom in a Storyboard to customize the views of the UITableView cell. To get a margin of 0 create the constraint as described with Standard or some value and edit the you cannot name the same as existing UITableViewCell properties like textLabel,  Change the table view's Content attribute (in the Attributes inspector) to Static Cells. Specify the number of sections for your table using the table view's Sections attribute. Set the Row attribute of each section to the number of rows you want. Configure each cell with the views and content you want.

  • No, you must not retain all your cells, because you must reuse your cells, and not load all cells to the memory, you must have only the cells that you are showing loaded!
  • @ggrana Since these are static cells we're dealing with, there aren't likely to be that many of them, so the memory usage will not be that significant. However, I do agree that your edited answer is better than mine, so I've upvoted it.
  • I did not know you can create IBOutlets from static cells. Have to dig more into documentation, I guess.
  • You don't need to declare an Outlet to the tableView since you're already using a UITableViewController.
  • a UITableView configured with 'Static cells' can only exist in the context of a UITableViewController.