How to refresh cell and add subview without showing separate line?
After reload cell - height is changing and in - (UITableViewCell *)tableView:(UITableView *)tableView_ cellForRowAtIndexPath:(NSIndexPath *)indexPath method I adding custom view to cell and the white separate line is appear but after scrolling TableView separate line is hidden
Related
In my tableViewCell, I am trying to display dynamic content from CoreData string object in a textView with a background image. When the tableView is loading for the first Time, background image is stretching to right and text content in textView is trimming, but when I scroll the tableView, rect of background image is appearing as expected however, textView content is still trimming. can anyone please tell me what default methods will system call internally when we scroll a tableView? Because some method is setting my background Image rect correctly which i am failing to set in initial loading of tableView.
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
Many more please check tableview data delegate and data source Methods.
Assume we have UITableView created in storyboard with prototype cells, it is required to change the structure of table cells (adjusting frames of labels in cell content) based on some calculations at loading the view, currently I change each cell in
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
after using dequeueReusableCellWithIdentifier: to load table cell,
but this is not efficient as each cell has to be modified individually, it would be much better if we could modify a loaded cell once and reuse the modified cell .
Any ideas ?
This could be useful:
Prefilling the UICollectionView cell reuse queue
UITableView dequeueReusableCellWithIdentifier Theory
I have a Tableview that has a UIView and a label inside each row, and this UITableView resize its rows using
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
Well, my problem is that when I resize the cell, its view is resized automatically too. How can I avoid resizing the view inside the cell?
The property autoresizesSubviews of your cells prevents any subviews within your cells to resize automatically. By setting it at NO, it should fix your problem.
cell.autoresizingMask = NO;
However, I would suggest using the method below when playing with the size of cells.
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
Good luck
You should set a proper autoresizing mask or autolayouts rules of the cell subviews, to obtain the layout you want for your cells
you can set the label's contentMode.
for example:
UILabel *lb...(create)
lb.contentMode=UIViewContentModeScaleToFill (change that ,)
cell addSubView:lb;
I have made a custom UITableViewCell, this cell has icons, labels and text views within it. I want to make the entire cell clickable but i can't make it work.
I use the following code to handle the click
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
This only works if you touch the cell where there are no textviews, how do i make the entire cell clickable?
The table view I have changes Cell background colors quite often. The colors set in -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath are fine but some colors are set after the table view loads like:
- (void) ChangeCellColorAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:currentCell inSection:0]];
cell.backgroundView.backgroundColor = [UIColor orangeColor];
}
If a cell is changed with that method it will revert back to what it was originally set to when it scrolls out of view. How can I insure it will stay the same color when I scroll out of view.
You should take into account how the cell loading process works: when you set the color of a visible cell and the user scrolls to a point where that cell is not visible, and then scrolls back to the original point the table view will call again tableView:cellForRowAtIndexPath:, a new cell will be created(better said an already created cell will be reused if you are doing things correctly as I assume) and the background color you previously set will be ignored.
The solution is to know which color each cell should have in tableView:cellForRowAtIndexPath: and set the color there.