How to create UITableViewCell with an next style (Right Detail in xib)
For example can I use next:
cell.style = 'Right Detail' (roughly)
Thanks!
style is a readonly property of UITableView . That means you can initialize a table as grouped or plane , but you cannot change the style afterwards. Save this answer.
The reuse identifier is associated with a UITableViewCell object that the table-view's delegate creates with the intent to reuse it as the basis (for performance reasons) for multiple rows of a table view. It is assigned to the cell object in initWithFrame:reuseIdentifier: and cannot be changed thereafter.
What you want is UITableViewCellStyleValue1
, but you can't set an existing cell's style: you have to set it when you're creating it. Like this:
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"YourIdentifier"];
While the best answer for this question is correct it doesn't touch on the topic of cell reuse.
It turns out you no longer have to use tableView.register
.
Instead you can use this approach:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
// Whenever there's a reusable cell available, dequeue will return it
let cell = tableView.dequeueReusableCell(withIdentifier: "cellIdentifier") ??
UITableViewCell(style: .subtitle, reuseIdentifier: "cellIdentifier")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With