Reputation: 7050
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.
How can i do it?
Upvotes: 1
Views: 252
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
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