Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I am making an app which uses tableView having TextView as a Cell in it. And it adds more cell on click of footer of the tableView.
Now i want to reload table when textView done the editing.For that i put the [tblView reloadData] in textViewShouldEndEditing but at this time table doesn't reload.
Please help me.
You need to verify that the textView.delegate is set to an instance of the class that implements textViewShouldEndEditing. If the TextView is in a UITableViewCell subclass, then you might be setting that subclass as the delegate for the UITextView, when in fact you've implemented the delegate methods on the view controller that contains the tableView.
One approach would be this:
Put your UITextView in a UITableViewCell subclass.
Implement the UITextViewDelegate methods in your view controller that contains the UITableView. (Which may, in itself, be a UITableViewController, but it could just be a UIViewController that has a UITableView in it; either one is fine.)
Make a relationship between the cell and the containing view controller using code similar to this:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath {
MyCustomCellSubclass *cell = [tableView dequeueReusableCellWithIdentifier....];
cell.textView.delegate = self;
// do further cell customization if needed
return cell;
}
Then when your cell's textView finishes, it'll call back to the containing view controller.
Also, from your description, it sounds like you might prefer the delegate method:
- (void)textViewDidEndEditing:(UITextView *)textView;
instead of "shouldEndEditing", but for what you're describing, that isn't your current problem.
As an added tip, if you do [tblView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewAnimationRowAutomatic], it'll refresh the tableview using a nice little animation, instead of a hard reload like reloadData does.
First Make sure you have UITextView Delegate for the self View. Like
UITextView.delegate = self ;
After that in
- (BOOL)textFieldShouldReturn:(UITextView *)theTextField {
if (theTextField == TextView) {
[Tableview Reload];
}
return YES;
}
Try this , Let me know.
Make sure your UITextView Delegate Methods are calling by putting NSLog try with using following Delegate Method of UITextView.
-(void)textViewDidEndEditing:(UITextView *)textView {
[textView resignFirstResponder];
[self performSelector:#selector(reloadTableViewData) withObject:nil afterDelay:0.3];
}
- (void)reloadTableViewData {
[self.tableView reloadData];
}
Related
I change the value of 2 UILabels in my "viewDidLoad" method, but I need the view to refresh after that in order to display the values. As it currently stands, the UILabels display the value of the previously selected cell. I need to do the refresh right after I change the labels' values. The "setNeedsDisplay" method is not doing the job.
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
_nameLabel.text = _selectedLocation.name;
_addressLabel.text = _selectedLocation.address;
[self.view setNeedsDisplay];
}
Based on your comments, I think you are trying to do something like:
- (void)updateLabelTexts {
_nameLabel.text = _selectedLocation.name;
_addressLabel.text = _selectedLocation.address;
}
and wherever you are changing the _selectedLocation values:
//Just an example
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
_selectedLocation = _yourLocationsArray[indexPath.row];
//now you call your update method
[self updateLabelTexts];
}
The point is that you have to call [self updateLabelTexts]; just after you update the values.
A very stupid bug. Turns out when I made the segue to transition into the next view, I actually dragged it from a physical cell on to the destination controller. However, I should've simply connected the sending uiview controller to the destination viewcontroller with the segue, and then manually handled the transition. That fixed it, so there's no need to "refresh or reload" the UIView as I was trying to do.
Ok so I have a custom animation being implemented inside willDisplayCell method. It is working fine when I scroll the view up and down. When I tap on one of the row, it will be pushed to another view controller to show more details and let user update the data.
The issue is when the user get back to the tableview. I called the [tableView reloadData] method inside the viewWillAppear to make sure updated data is shown. This will trigger the animation transition that I set up earlier.
My question is: Is there a way to only perform the animation when user scroll up/down the tableview, not when the reloadData is called?
If there's a way to mix between the willDisplayCell with scrollViewDidScroll or something along that line, it would be awesome.
Thanks!
The easiest solution would be to add a state flag that would tell the willDisplayCell whether it should actually animate.
Add a property to your UITableViewDelegate:
#property (nonatomic) BOOL shouldPreventDisplayCellAnimation;
Set the property before and after calling reloadData:
- (void)viewWillAppear:(BOOL)animated
{
…
self.shouldPreventDisplayCellAnimation = YES;
[self.tableView reloadData];
self.shouldPreventDisplayCellAnimation = NO:
}
Modify willDisplayCell to animate on condition
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (!self.shouldPreventDisplayCellAnimation) {
//animate
}
}
I created a custom UITableViewCell subclass with multiple fields and some other properties. Since I used this new cell in my UITableViewController, the cells do not react on the "swipe to delete" gesture.
To test if I'm missing something in my delegate I added a plain standard UITableView to my xib, hooked up dataSource and delegate and returned a regular UITableViewCell from -tableView:cellForRowAtIndexPath: this enabled the gesture again.
I searched on the net and one suggested to plain implement -layoutSubviews which didn't work too.
Is there something I would have to implement in my subclass?
After hours of searching and not finding anything on the internet, I did a whole day trial and error to find out that in my XIB the Editing was set to Multiple Selection During Editing.
I didn't know that this would disable the "Swipe-To-Delete-Functionallity".
As I need both possibilities (s2d unless editing and multiple selection while editing) I added these two lines in my -toggleEditing: method:
if(![_tableView isEditing]) {
[_tableView setAllowsMultipleSelectionDuringEditing:YES]; // <----
[_tableView setAllowdSelectionDuringEditing:YES]; // <----
[_tableView setEditing:YES animated:YES];
}
else {
[_tableView setAllowsMultipleSelectionDuringEditing:NO]; // <----
[_tableView setAllowdSelectionDuringEditing:NO]; // <----
[_tableView setEditing:NO animated:YES];
}
I have a UITableView with a UITextField inside of each cell. A model object that stores the index of the cell that is currently being edited. If the cell scrolls off-screen, my app takes away first-responder status. (Failing to do so may cause problems). Now, suppose a cell (possibly the same one, or possibly a different one) corresponding to that index is about to scroll back onto the screen. I want to make that cell's textField the firstResponder. My delegate does receive a call
tableView: willDisplayCell: forRowAtIndexPath:
corresponding to the new cell. However, calling becomeFirstResponder: at that point does not help as the cell won't accept firstResponder status until it has been displayed.
Short of using a timer, any ideas for how to call becomeFirstResponder: at a point when the cell is in fact able to become the first responder?
EDIT: cellForRowAtIndexPath: is always called before willDisplayCell:. So no help there.
I haven't tried this, but the first thing I'd try is in cellForRowAtIndexPath...
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// standard stuff to build cell and setup it's state
if ([indexPath isEqual:self.myModel.indexPathOfTextFieldBeingEdited]) {
// you probably have a handle to the text field from the setup above
UITextField *textField = (UITextField *)[cell viewWithTag:SOME_TAG];
[textField performSelector:#selector(becomeFirstResponder) withObject:nil afterDelay:0.0];
}
return cell;
}
You have to show cell on the screen to make it as first responder. Do at first:
[self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionMiddle animated:NO];
and then call first responder on it's label/textField.
Here's what I did in MonoTouch - it's important that you do not animate the ScrollToRow() - i.e. "animated:NO" as shown in the answer by edzio27 (thanks edzio27 :) ).
var newCell = (UIOrderLineCell)tableView.CellAt(newIndexPath);
if (newCell == null)
{
tableView.ScrollToRow(newIndexPath, UITableViewScrollPosition.Middle, false);
newCell = (UIOrderLineCell)tableView.CellAt(newIndexPath);
}
FYI - Noob iOS developer here.
My current setup is a UIViewController with a UIView within, then a UITableView within the UIVIew. So it goes like this...
UIViewController --> UIView --> UITableView
The reason for this is because I have other elements wrapped with the tableview. The UIViewController loads dynamic content into the table view. I have a segmented Control in which I want to use to switch the content within the table view.
I've read something on [table reload] and [table beginUpdate] but don't understand how to use it. Any help would be great.
You need to implement a method for UIControlEventValueChanged event ofUISegmentedControl for this.
[yourSegmentedControl addTarget:self action:#selector(segmentChanged:) forControlEvents:UIControlEventValueChanged];
And implement the segmentChanged method like:
- (void)segmentChanged:(id)sender
{
UISegmentedControl *mySegment = (UISegmentedControl *)sender;
switch ([mySegment selectedSegmentIndex])
{
case 1:
//load first contents
break;
case 2:
//load second contents
break;
default:
break;
}
[self.yourTableView reloadData];
}
Ok, so [table reloadData] will reload the data (so if you change the data and want to update the table with the necessary data call this), but straight after you call that make sure to call [table setNeedsDisplay] to refresh the UI.[table beginUpdates]
begins a series of method calls that insert, delete, or select rows and sections of the receiver. You end the processes with [table endUpdates];
Make sure you set your table view's dataSource and delegate to self, this can be done through the xib and programmatically like this:
[table setDelegate: self];
or
[table setDataSource: self];
As said:
Call this delegate method for UISegmentedControl
- (void)segmentedControl:(UISegmentedControl*)segmentedControl didSelectIndex:(NSUInteger)selectedIndex
{
if(selectedIndex == 0)
{
// Update the data
}
else if(selectedIndex == 1)
{
// Update the data
}
[table reloadData];
[table setNeedsDisplay];
}
For example,
Your UIView named *myView and your UITableView named *myTableView,
the time you want to reload tableview, in your UIViewController , you should reload tableview like this:
[self.myView.myTableView reload];
and make sure tableview's delegate and dataSourceDelegate is set correctly.
Need to set the delegate & data source for tableview in ViewController.h file like
UITableViewDataSource, UITableViewDelegate.
Implement delegate & datasource methods in ViewController.m file
[tableview SetDelagate:self];
[tableview SetDatasource:self];
Implement the delegate methods.
And reload the table using
[tableView reloadData];
method.