Is it possible to keep the contentView.frame always the same, regardless of tableView.editing? I already tried to override layoutSubviews and willTransitionToState but those options fizzled out too. I can't seem to be able to change the width of the contentView. Or maybe my approach ist just plain impossible ...
Maybe there is another way to solve this.
The behaviour I want to achieve is the following: I want the standard textLabel of a UITableViewCell to be always indented and not change position when the tableView enters editing mode. The problem I will probably face is that the behaviour of the detailTextLabel will have to be corrected (e.g. truncation of text if textLabelcontent is too long). The reason why I don't want to implement my own UILabelis because a custom subviews will decrease the scrolling performance by a significant amount.
I hope that anyone already implemented something like this in their UITableViewand could show me a solution to this tedious problem. Thanks in advance!
EDIT: I'm dealing with a UITableView in plain and not grouped style.
Use the UITableViewDelegate method:
- (BOOL)tableView:(UITableView *)tableView
shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath
{
return NO;
}
This will work for both grouped and non-grouped UITableView types. However, if you have a grouped tableview, you can use this property on the cell:
cell.shouldIndentWhileEditing = NO;
Luckily, iOS is perfectly equipped to keep whatever value constant.
This (ugly) piece of code will keep the frame fixed to whatever value has origin.x==0. This is easily adapted to your particular needs.
// put this in your UITableViewCell subclass
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
NSLog(#"observed value for kp %# changed: %#",keyPath,change);
if ( [keyPath isEqual:#"frame"] && object == self.contentView )
{
CGRect newFrame = self.contentView.frame;
CGRect oldFrame = [[change objectForKey:NSKeyValueChangeOldKey] CGRectValue];
NSLog(#"frame old: %# new: %#",NSStringFromCGRect(oldFrame),NSStringFromCGRect(newFrame));
if ( newFrame.origin.x != 0 ) self.contentView.frame = oldFrame;
}
}
// add the cell as an observer for frame changes, somewhere in initialization:
[self.contentView addObserver:self forKeyPath:#"frame" options:NSKeyValueObservingOptionOld context:nil];
// IMPORTANT: remove the cell as an observer in -dealloc:
[self.contentView removeObserver:self forKeyPath:#"frame"];
This will only allow the frame to change to values with an origin.x==0. Remove the NSLog() lines for Release builds.
I have tested this for a few minutes and haven't seen any side effect.
Based on Usman.3D
On the storyboard, a property indent While Editing is checked by default. It can be unchecked manually. It equals to cell.shouldIndentWhileEditing = NO.
You will have to override layoutSubviews to do this. It applies for the level of custom indentation so it does for none.
Please have a look at How can I change the amount of indentation on my custom UITableViewCell while editing?. I provided an example how to change the level of indentation. Though it didn't work 100% for the OP it worked in my example app. I think this will point you in the right direction.
I had the same trouble with my plain style table even with shouldIndentWhileEditingRowAtIndexPath returning NO
On my side, I encounter the issue because my first row should not be deleted and the rest of the table view cells should.
I added this second method and it worked:
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == 0 && indexPath.section == 0) return NO;
return YES;
}
Hope it helps
Have you looked at UITableViewCell's shouldIndentWhileEditing and indentationLevel properties? Those might sort it.
A little late,
but I solved the problem by switching off the Autoresizing Mask for all views in my TableViewCell:
[<viewInCell> setAutoresizingMask:UIViewAutoresizingNone];
Or switch off Autoresizing of width and/or height directly in Interface Builder.
Just came across this as I was researching the same problem.
A very easy solution is to set the indentation level to a negative number - it is a signed integer after all.
A [cell setIndentationLevel:-3] worked perfectly for me, given a default indentation width of 10, to move the label back to the left in a plain table.
You can always get a tableviewcell with an indexpath. Using that tableviewcell reuseidentifier, You can avoid the tableview cell content size to be resized or not. I had a requirement to implement the similar kind of functionality to avoid resizing of seperate cells. PFB the code.
-(BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath{
BOOL shouldIndentWhileEditingRow = NO;
UITableViewCell *lTableViewCell = [tableView cellForRowAtIndexPath:indexPath];
/*Change the position of the target rect based on Sending messages or Receiving messages*/
if ([lTableViewCell.reuseIdentifier isEqualToString:#"SendingChatCellIdentifier"]) {
shouldIndentWhileEditingRow = NO;
}else if ([lTableViewCell.reuseIdentifier isEqualToString:#"ReceivingChatCellIdentifier"]){
shouldIndentWhileEditingRow = YES;
}
return shouldIndentWhileEditingRow;
}
Related
I'm trying to mimic the iMessage bubble text behaviour with an UITableView. In order to always scroll to the bottom I'm using scrollToRowAtIndexPath when viewDidLoad and viewDidAppear. This is because when the viewDidLoad method is called, the table has not been completely loaded, so I need that extra scroll in viewDidAppear. This code makes the trick. However, what I want is not an animated scroll (setting animated to NO does not solve this), I want the table to be displayed always from the bottom, not load the table and then go to the last row.
Is this possible? I can't find any solution that fits completely with the desired behaviour.
This is the best solution!
Just reverse everything!
tableView.transform = CGAffineTransformMakeRotation(-M_PI);
cell.transform = CGAffineTransformMakeRotation(M_PI);
Swift 4.0:
tableView.transform = CGAffineTransform(rotationAngle: -CGFloat.pi)
cell.transform = CGAffineTransform(rotationAngle: CGFloat.pi)
Be careful though, because now the headerView and footerView positions are reversed as well.
You can avoid the call from viewDidLoad because scrolling from within viewDidAppear makes that first call redundant. viewDidAppear is called every time you navigate back to the view but viewDidLoad is only called once when the view is initialized.
I would agree with earlier suggestions of hiding the scroll from the user instead of changing the way a UITableView is loading data. My suggestion would be to use the scrollToRowAtIndexPath method in the viewWillAppear method with animation set to NO. After that if you have to add a new row while the table is visible to the user, use insertRowsAtIndexPaths:withRowAnimation: to add a row at the bottom of the table view. Be sure to take care of adding the data at the end of your data model so that when the user navigates away and comes back, s/he comes back to the same layout.
Hope this helps.
edit:
Just saw your reason for not accepting the previous answers and thought I'd elaborate a little more. The solution I propose would require minimum effort, avoid calling reloadData time and again and thus avoid calling the scrollToRowAtIndexPath method again and again. You only need to make one call to scrollToRowAtIndexPath in viewWillAppear to scroll to the bottom of the table view (hiding the transition from the user when doing so) and you wouldn't need to do that again.
I do something similar in an RPN calculator I've built. I have a table view with all the numbers in it and when a number is added to the stack, everything pops up one cell. When I load the view I call:
[self.myTableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:NumOfStackItems - 1 inSection:0]
atScrollPosition:UITableViewScrollPositionTop animated:NO];
In my viewWillAppear. This way my table view starts shown at the bottom of the stack and no animation is seen. By putting this in the viewWillAppear, every time I navigate to the view, it shows up at the bottom of the table.
When I add numbers to the stack, I just add it in an array that holds all the numbers and then put the text in the proper row like this:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// Cell initialization here...
NSUInteger row_num = [indexPath row];
cell.rowNumber.text = [NSString stringWithFormat:#"%g", [DataArray objectAtIndex:NumberOfStackItems-row_num-1];// subtract the row number off to get the correct array index
return cell
}
I also make sure that whenever I update the tableview with a new value i first call the reloadData function, and then call the scrollToRowAtIndexPath function I cited above, this way I stay at the bottom of the table.
You can have your UITableView hidden on viewDidLoad, and then change it to visible on viewDidAppear right after you scroll the table to the bottom. This way the user won't see the scrolling animation.
The solution is to override viewWillAppear and let it scroll (non-animated) to the bottom:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self goToBottom];
}
-(void)goToBottom
{
NSIndexPath *lastIndexPath = [self lastIndexPath];
[self.tableView scrollToRowAtIndexPath:lastIndexPath atScrollPosition:UITableViewScrollPositionBottom animated:NO];
}
-(NSIndexPath *)lastIndexPath
{
NSInteger lastSectionIndex = MAX(0, [self.tableView numberOfSections] - 1);
NSInteger lastRowIndex = MAX(0, [self.tableView numberOfRowsInSection:lastSectionIndex] - 1);
return [NSIndexPath indexPathForRow:lastRowIndex inSection:lastSectionIndex];
}
By performing this at viewWillAppear it will be done before the user sees the table.
You can fix it by making an invisible footer and do the calculations in there. When the footer is loaded the contentSize is updated. To make it scroll I check set the contentOffset of the tableview.
I have commented out the animation part, since you wanted it without, but it also works.
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return 1;
}
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
if( tableView.contentOffset.y != tableView.contentSize.height - tableView.frame.size.height && automaticScroll ){
//[UIView animateWithDuration:0.0 animations:^{
self.contentTableView.contentOffset = CGPointMake(0, tableView.contentSize.height - self.contentTableView.frame.size.height);
//} completion:^(BOOL finished) {
[tableView reloadData];
//}];
automaticScroll = NO;
}
UIView *emptyFooter = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 1)];
emptyFooter.backgroundColor = [UIColor clearColor];
return emptyFooter;
}
I created a BOOL automaticScroll to trigger the scroll to the bottom. This should be set in the viewWillAppear method, or whenever you load the data and reload the tableView.
If you want to add rows, you also need to set the BOOL, like:
-(void)addItemButtonClicked:(id)sender
{
automaticScroll = YES;
//Add object to data
[self.contentTableView reloadData];
}
If you need more help, please let me know.
scrollToRowAtIndexPath
use to scroll the row in tableview to particular position
just change content inset after load data to move content view of table view if height is less than parent view.
[self.tableView reloadData];
[self.tableView setContentInset:UIEdgeInsetsMake(self.view.frame.size.height - self.tableView.contentSize.height < 0 ? 0 : self.view.frame.size.height - self.tableView.contentSize.height, 0, 0, 0)];
Swift 3.1
tableView.transform = CGAffineTransform(rotationAngle: CGFloat.pi)
cell.transform = CGAffineTransform(rotationAngle: CGFloat.pi)
Credits: #Christos Hadjikyriacou
I have a plain (not grouped) tableView with custom cells, and when I hit the Edit button, the cells indent. I don't want that, I want the deletion sign to lay right on top of my cell.
I tried shouldIndentWhileEditingRowAtIndexPath and also cell.shouldIndentWhileEditin = NO; as well as cell.indentionLevel = -3, but both won't have any effect. Any idea why?
Could this be due to my setup? I followed this tutorial, and I also tried a setup like Davyd suggested here, but the last did not only still indent my cells, it made it even worse, as the cells were indented, when I press Done.. and I can't get the background image to cover the whole cell...
So, anyone knows how to stop custom cells in a plain tableview from intending, while still showing the delete and move sign?
//EDIT:
btw, I build the custom cell in IB. I can take away the checkmark saying "Indent while Editing", it doesn't care. I can change the values for indention level and width, no effect. If i change the editing accessory, it happily displays it.
Hope that helps..
Thanks!
After a lot of research and trying pixel by pixel, it turned out, I needed to use -(void)layoutSubviews to "transit" from the original state to the original size.. If someone else ever needs to do that, here's my code, placed in my CustomCell.m:
- (void)willTransitionToState:(UITableViewCellStateMask)aState
{
[super willTransitionToState:aState];
self.state = aState;
}
- (void)layoutSubviews
{
[super layoutSubviews];
// no indent in edit mode
self.contentView.frame = CGRectMake(0,
self.contentView.frame.origin.y,
self.contentView.frame.size.width,
self.contentView.frame.size.height);
if (self.editing )
{
NSLog(#"subview");
float indentPoints = self.indentationLevel * self.indentationWidth;
switch (state) {
case 3:
self.contentView.frame = CGRectMake(indentPoints,
self.contentView.frame.origin.y,
self.contentView.frame.size.width +124,// - indentPoints,
self.contentView.frame.size.height);
break;
case 2:
// swipe action
self.contentView.frame = CGRectMake(indentPoints,
self.contentView.frame.origin.y,
self.contentView.frame.size.width +75,// - indentPoints,
self.contentView.frame.size.height);
break;
default:
// state == 1, hit edit button
self.contentView.frame = CGRectMake(indentPoints,
self.contentView.frame.origin.y,
self.contentView.frame.size.width +80,// - indentPoints,
self.contentView.frame.size.height);
break;
}
}
}
Hope that helps :)
None of the above works for me, but this did:
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
return UITableViewCellEditingStyleNone;
}
This way your saying to the UITableView that you dont want any native styling when in edit mode, and instead you can take care of it yourself.
Have you checked that the delegate method tableView:shouldIndentWhileEditingRowAtIndexPath: is being called when you edit the cell?
The only time I used the tableView:shouldIndentWhileEditingRowAtIndexPath: delegate method
it worked fine.
// Override to prevent indentation of cells in editing mode (in theory)
- (BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath {
return NO;
}
Try changing the autoresizing mask of your content view or the elements inside your cell. The indent is because when your cell enters editing mode the content view is resized to show the accessories and the content moves with it.
It's hard to give specific advice without knowing what's in your cell, but you want to look at the fixed left or right margins.
I had the same problem. The reason is: They're not indented but auto-resized. The remove button is shown an the cell's view (and its subviews) are resized.
Solution is: Set the autosizing behavior of the custom table cell's subviews (the labels or whatever you placed on it) in InterfaceBuilder/Xcode as you need it.
I just realized that if you connect a UIView to the backgroundView outlet, it doesn't move at all. That combined with autoresizing flags is really all you need, I think.
Just tried this on iOS 6.
The shouldIndentWhileEditingRowAtIndexPath delegate method now works on plain table view as well.
----Edited-----
Well, as it turned out, it doesn't indent only if allowsMultipleSelection = YES
I've implemented Cocoa with Love's example for Multi-row selection which involves creating a custom UITableViewCell that initiates an animation in layoutSubviews to display checkboxes to the left of each row, like so:
- (void)layoutSubviews
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationBeginsFromCurrentState:YES];
[super layoutSubviews];
if (((UITableView *)self.superview).isEditing)
{
CGRect contentFrame = self.contentView.frame;
contentFrame.origin.x = EDITING_HORIZONTAL_OFFSET;
self.contentView.frame = contentFrame;
}
else
{
CGRect contentFrame = self.contentView.frame;
contentFrame.origin.x = 0;
self.contentView.frame = contentFrame;
}
[UIView commitAnimations];
}
This works fine and for all intents and purposes my UITableView acts as it should. However I'm running into a small aesthetic issue: when scrolling my UITableView rows which have not previously been displayed will initiate their sliding animation, meaning the animation is staggered for certain rows as they come into view.
This is understandable, given that setAnimationBeginsFromCurrentState has been set to YES and rows further down in the UITableView have yet to have their frame position updated. To solve the issue, I attempted to use willDisplayCell to override the animation for cells which become visible while the UITableView is in edit mode. Essentially bypassing the animation and updating the rows frame immediately, so as to make it appear as if the cell has already animated into place, like so:
/*
Since we animate the editing transitions, we need to ensure that all animations are cancelled
when a cell is scheduled to appear, so that things happen instantly.
*/
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
[cell.contentView.layer removeAllAnimations];
if(tableView.isEditing) {
CGRect contentFrame = cell.contentView.frame;
contentFrame.origin.x = EDITING_HORIZONTAL_OFFSET;
cell.contentView.frame = contentFrame;
} else {
CGRect contentFrame = cell.contentView.frame;
contentFrame.origin.x = 0;
cell.contentView.frame = contentFrame;
}
}
Unfortunately this doesn't seem to have any effect. Does anyone have any idea as to how I can solve this issue?
Not sure if you still need an answer to this question but I just ran into the exact same issue so I thought that I would share my solution. I implemented Multi-Selection the same way its described in the Cocoa with Love blog post that you mentioned.
In the cellAtIndexPath DataSource method when I create a new cell (not if the cell is already in the Queue of reusable cells) I check if the tableView is in editing mode and if it is I set a property on the cell (I created my own custom cell with an EnableAnimation property) to false so when it gets the SetEditing callback it will not animate the cell, instead it will just set the frame. In the constructor of the Cell class I set EnableAnimation to true, when the SetEditing callback is called I set EnableAnimation to the animate argument that is passed in. I hope this helps.
I have implemented a custom UITableViewCell which includes a UITextView that auto-resizes as the user types, similar to the "Notes" field in the Contacts app. It is working properly on my iPhone, but when I am testing it in the iPad, I am getting some very strange behavior: When you get to the end of a line, the keyboard hides for a millisecond and then shows itself again immediately. I would write it off as just a quirky bug, but it actually causes some data loss since if you are typing, it loses a character or two. Here's my code:
The Code
// returns the proper height/size for the UITextView based on the string it contains.
// If no string, it assumes a space so that it will always have one line.
- (CGSize)textViewSize:(UITextView*)textView {
float fudgeFactor = 16.0;
CGSize tallerSize = CGSizeMake(textView.frame.size.width-fudgeFactor, kMaxFieldHeight);
NSString *testString = #" ";
if ([textView.text length] > 0) {
testString = textView.text;
}
CGSize stringSize = [testString sizeWithFont:textView.font constrainedToSize:tallerSize lineBreakMode:UILineBreakModeWordWrap];
return stringSize;
}
// based on the proper text view size, sets the UITextView's frame
- (void) setTextViewSize:(UITextView*)textView {
CGSize stringSize = [self textViewSize:textView];
if (stringSize.height != textView.frame.size.height) {
[textView setFrame:CGRectMake(textView.frame.origin.x,
textView.frame.origin.y,
textView.frame.size.width,
stringSize.height+10)]; // +10 to allow for the space above the text itself
}
}
// as per: https://stackoverflow.com/questions/3749746/uitextview-in-a-uitableviewcell-smooth-auto-resize
- (void)textViewDidChange:(UITextView *)textView {
[self setTextViewSize:textView]; // set proper text view size
UIView *contentView = textView.superview;
// (1) the padding above and below the UITextView should each be 6px, so UITextView's
// height + 12 should equal the height of the UITableViewCell
// (2) if they are not equal, then update the height of the UITableViewCell
if ((textView.frame.size.height + 12.0f) != contentView.frame.size.height) {
[myTableView beginUpdates];
[myTableView endUpdates];
[contentView setFrame:CGRectMake(0,
0,
contentView.frame.size.width,
(textView.frame.size.height+12.0f))];
}
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
int height;
UITextView *textView = myTextView;
[self setTextViewSize:textView];
height = textView.frame.size.height + 12;
if (height < 44) { // minimum height of 44
height = 44;
[textView setFrame:CGRectMake(textView.frame.origin.x,
textView.frame.origin.y,
textView.frame.size.width,
44-12)];
}
return (CGFloat)height;
}
The Problems
So, here's what's happening
This code is working 100% properly on my iPhone and in the iPhone simulator. As I type the text, the UITextView grows smoothly, and the UITableViewCell along with it.
On the iPad simulator, however, it gets screwy. It works fine while you are typing on the first line, but when you get to the end of a line, the keyboard disappears and then reappears immediately, so that if the user continues typing the app misses a character or two.
Here are some additional notes on the weird behaviors that I have noticed which may help explain it:
Also, I have found that removing the lines [myTableView beginUpdates]; [myTableView endUpdates]; in the function textViewDidChange:(UITextView *)textView makes the UITextView grow properly and also doesn't show and hide the keyboard, but unfortunately, then the UITableViewCell doesn't grow to the proper height.
UPDATE: Following these instructions, I am now able to stop the strange movement of the text; but the keyboard is still hiding and showing, which is very strange.
Does anyone have any ideas as to how to get the keyboard to continually show, rather than hide and show when you get to the end of the line on the iPad?
P.S.: I am not interested in using ThreeTwenty.
you should return NO in:
-(BOOL) textViewShouldEndEditing:(UITextView *)textView
if you would like to show keyboard at all times. You should handle cases, which keyboard should be hidden, by returning YES to this delegate function.
edit:
I dug a little more, when [tableView endUpdates] called, it basically does 3 things :
Disables user interaction on the tableView
Updates cell changes
Enables user interaction on the tableView
The difference between SDKs(platforms) is at [UIView setUserInteractionEnabled] method. As UITableView does not overrite setUserInteractionEnabled method, it is called from super (UIView).
iPhone when setUserInteractionEnabled called, looks for a private field _shouldResignFirstResponderWithInteractionDisabled which returns NO as default, so does not resign the first responder (UITextView)
But on iPad there is no such check AFAIK, so it resignes UITextView on step 1, and sets focus and makes it first responder on step 3
Basically, textViewShouldEndEditing, which allows you to keep focus, according to SDK docs, is your only option ATM.
This method is called when the text
view is asked to resign the first
responder status. This might occur
when the user tries to change the
editing focus to another control.
Before the focus actually changes,
however, the text view calls this
method to give your delegate a chance
to decide whether it should.
I had the same issue for an iPad app and came up with another solution without having calculating the height of the text itself.
First create a custom UITableViewCell in IB with an UITextField placed in the cell's contentView. It's important to set the text view's scrollEnabled to NO and the autoresizingMask to flexibleWidth and flexibleHeight.
In the ViewController implement the text view's delegate method -textViewDidChanged: as followed, where textHeight is a instance variable with type CGFloat and -tableViewNeedsToUpdateHeight is a custom method we will define in the next step.
- (void)textViewDidChange:(UITextView *)textView
{
CGFloat newTextHeight = [textView contentSize].height;
if (newTextHeight != textHeight)
{
textHeight = newTextHeight;
[self tableViewNeedsToUpdateHeight];
}
}
The method -tableViewNeedsToUpdateHeight calls the table view's beginUpdates and endUpdates, so the table view itself will call the -tableView:heightForRowAtIndexPath: delegate method.
- (void)tableViewNeedsToUpdateHeight
{
BOOL animationsEnabled = [UIView areAnimationsEnabled];
[UIView setAnimationsEnabled:NO];
[table beginUpdates];
[table endUpdates];
[UIView setAnimationsEnabled:animationsEnabled];
}
In the table view's -tableView:heightForRowAtIndexPath: delegate method we need to calculate the new height for the text view's cell based on the textHeight.
First we need to resize the text view cells height to the maximum available height (after subtracting the height of all other cells in the table view). Then we check if the textHeight is bigger than the calculated height.
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
CGFloat heightForRow = 44.0;
if ([indexPath row] == kRowWithTextViewEmbedded)
{
CGFloat tableViewHeight = [tableView bounds].size.height;
heightForRow = tableViewHeight - ((kYourTableViewsNumberOfRows - 1) * heightForRow);
if (heightForRow < textHeight)
{
heightForRow = textHeight;
}
}
return heightForRow;
}
For a better user experience set the table view's content insets for bottom to e.g. 50.0.
I've tested it on the iPad with iOS 4.2.1 and works as expected.
Florian
I have a custom UITableViewCell with a UIScrollView in it that is wired to the cell controller. When I assign text to the scrollview, some cells get the correct text, some are blank, some redisplay old text and others have the scrollview clipped around the 2nd or 3rd line of text. It seems random on what will happen. I followed the suggestion here of using a timer to fix blank cells, http://www.bdunagan.com/2008/12/08/uitextview-in-a-uitableview-on-the-iphone/, but that didn't help. I placed the timer code in the cellForRowAtIndexPath method.
I've also tried calling
[cell.textview setNeedsDisplay];
after text is assigned to the textview but it doesn't have any affect.
When I use a textfield or label, everything looks fine. However, I need something that can scroll text. Any suggestions on a fix or better way?
Update: Found this on the dev forums (specifically mentions your problem):
https://devforums.apple.com/message/38944#38944
I would follow the link it has some more detailed info.
// view controller
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
NSArray* visibleCells = [self.tableView visibleCells];
for (UITableViewCell* cell in visibleCells)
{
if ([cell.reuseIdentifier isEqualToString:kTextViewCellID])
{
[(MTextViewCell*)cell refresh];
}
}
}
// MTextViewCell
- (void)refresh
{
// mucking with the contentOffset causes the textView to redraw itself
CGPoint contentOffset = mTextView.contentOffset;
CGPoint contentOffset1 = { contentOffset.x, contentOffset.y + 1.0f };
mTextView.contentOffset = contentOffset1;
mTextView.contentOffset = contentOffset;
}
Try calling:
[tableView reloadData];
After you update all the textViews.