Fire Fist
Fire Fist

Reputation: 7050

Custom Cell.accessoryView of UITableView showing only first row in iOS

Hello i need to add custom cell accessoryView in my app.

Here is my code for custom cellAccessorView.

self.viewOfAccessory = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 70, 55)];
self.lblDay.text = @"Monday";
[self.viewOfAccessory addSubview:self.lblDay];
cell.accessoryView = self.viewOfAccessory;

However it showing only in first row. Not in every row of tableView.

I want to do like following pic.

enter image description here

How can i do it?

Upvotes: 1

Views: 252

Answers (2)

Walter R
Walter R

Reputation: 543

I believe the problem might be because you're calling elements as part of "self" and then adding them again in "self" (which should be the tableViewController), try this:

UIView* viewOfAccessory = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 70, 55)];
//Get the text from lblDay label, check if the "self." is necessary
self.lblDay.text = @"Monday"; //Not sure about this line since I don't have the whole code
[viewOfAccessory addSubview: lblDay];
cell.accessoryView = viewOfAccessory;

Upvotes: 1

Jake Spencer
Jake Spencer

Reputation: 1127

A view can only be added in one place. You are using the self.viewOfAccessory property to define what you want shown and then trying to add it to all of your cells. However, self.viewOfAccessory will only show up in one place. If you add it somewhere else (i.e. another row) it will just be moved. You need to be creating separate views and adding them to each cell.

Upvotes: 3

Related Questions