I have tableview in UIViewController & I have added text filed in prototype cell. I can't be able to scroll the table view when I am dragging the text filed area in the table view. When I am hiding the text field or making user interaction disable of the text filed on that time I am able to scroll the tableview.
Any resolution will be appreciated.
Thanks.
If the text field has userInteractionEnabled set to YES, and it fills the entire cell, you can not get the cell to listen to touch. In order to get the cell to respond to touches, you need to set the userInteractionEnabled of the text field to NO.
And if you want to make the text field editable, when the cell is selected, add the following code in didSelectRowAtIndexPath: method,
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// get the reference to the text field
[textField setUserInteractionEnabled:YES];
[textField becomeFirstResponder];
}
or
you have not make textField so large that it covers whole cell
Hope this will help :)
Related
I have a UITextField in one of my collection view cells. I want it to become first responder as soon as that cell is on screen.
So, I call [cell.textField becomeFirstResponder] in cellForItemAtIndexPath. However, this only works when the app is opened (the cell containing the uitextfield is already visible on app launch), if I scroll away from the cell and than scroll back to it, the textfield does not become first responder anymore.
What could be the problem?
EDIT: I am programatically scrolling the collection view to the cell containing the UITextField before calling becomeFirstResponder
It seems as the scrolling of the collection view made the collection view the first responder until the scrolling finished, so I made my textfield the first responder in this delegate method:
-(void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView
You should put the code in the
- (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath
function as according to the class ref:
Tells the delegate that the specified cell is about to be displayed in the collection view.
I developed custom cell. which have one UITextfield. i want to clear textfield text on UIButton event. UIButton is also in tableView in another section.
i also tried visible cells but it's clear text only visible cells
so how can i clear all cell's textfield?
Can anyone help me?
Thanks
I was not got all cells but i reload tableView on my Button Event.
On CellForRowAtIndexPath
I was set txtField.text = #"";
I make one UITableView Controller had static cell. And I set number of rows 3 in Storyboard. But rows does not set 3, just be made more and more like this screen shot. I don't touch any programatic code. Did I have to make it programmatically?
That's the normal behavior of a UITableView. Even though you only have 3 rows, the view itself extends to the bottom, and it shows where the cells would be if you had data in them. To fix, do one of two things: customize the UITableView so the dividing line between cells is invisible [UIColor clearColor], or change the size of the UITableView's height depending on how many cells you have.
If you add a footerView to the UITableView then it will not extend all the way to the bottom.
I solve this problem on the story board.
Create one more cell. if you want 3cells, then make 4cells.
Make whatever you want on cell. put the UIButton or UILabel any way. But except 4th cell.
Expend your 4th cell's height, to the bottom.
And finally, check hidden in attributes inspector. It makes 4th cell hidden.
That's it!
And I add one image file. I hope it help your work. Thanks.
Simple solution is to set footer's frame to nil:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
/*........*/
tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
return cell;
}
I would use a regular View Controller and insert a TableView of the required table height.
Then if you really want to you can do stuff with the cell height and label sizes.
I have a tableview with multiple dynamic tableview cells, and inside each tableviewcell i have multiple textfields. Each cell has a different tag, but the texfields don´t! and i need to retrieve the information the user will insert later on them. I´m using the interface builder.
Is it possible to access a texfield that isn´t tagged?.
Can i manage this using the "user defined Runtime Attributes"?.
Thanks
This is a common mistake when starting with iOS.
You should not be referring directly to the textfield in order to retrieve the information stored in it, especially in a table view. In a table view, when a cell scrolls off the screen, the cell will very likely get reused and the information that was stored there is gone forever.
Instead, store the text when the user finishes editing the textfield by setting your view controller as the textfield delegate and then implementing the textFieldDidEndEditing: delegate method:
- (void)textFieldDidEndEditing:(UITextField *)textField
{
// Store the textField.text value somewhere for later use.
}
You can go over each cell subviews and check if it a UITextField, something like:
for (UIView *subview in cell.subviews) {
if ([subview isKindOfClass:[UITextField class]]) {
// do something with the text field...
}
}
Having said that, this is probably not the best approach... U will do better given each textField a tag or subclassing the cell with a custom cell that has textFields as properties.
i am using custom UitableViewcell (MainTablecell)to display the records. i am also providing edit and delete functionality.so that i want to shrink my custom table cell, can any one suggest me how to do this.my custom cell looking like bellow
cell.shouldIndentWhileEditing = YES;
and
-(BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}
i tried with above poece of code but
Both are not working for me,How can i shrink all lables in my cell could you please help for me
When your tableView goes into edit mode, resize the labels.
shouldIndentWhileEditing: only makes the left side of the cell indent and does nothing for the content. You will need to manually resize the labels.
Depending on the design and code of that custom cell, you can call the label and perform setFrame: when in editing mode, just detect that mode and reload your tableView.