How to obtain the row currently clicked out of the data source and proxy event of tableView

Source: Internet
Author: User

[Cpp] view plaincopy
<Pre name = "code" class = "cpp"> NSIndexPath * indexPathOfOwnerCell = nil;
/* Also, make sure the selected text field is visible on the screen */
// Obtain the total number of cells in each section.
NSInteger numberOfCells = [self. myTableView. dataSource
TableView: self. myTableView
NumberOfRowsInSection: 0];
NSLog (@ "numberOfCells = % d", numberOfCells );
/* So let's go through all the cells and find their accessory text fields.
Once we have the refernece to those text fields, we can see which one
Them is the first responder (has the keyboard) and we will make a call
To the table view to make sure after the keyboard is displayed,
That specific cell is NOT obstructed by the keyboard */
For (NSInteger counter = 0;
Counter <numberOfCells;
Counter ++ ){
NSIndexPath * indexPath = [NSIndexPath indexPathForRow: counter
InSection: 0];
UITableViewCell * cell = [self. myTableView cellForRowAtIndexPath: indexPath];
UITextField * textField = (UITextField *) cell. accessoryView;
If ([textField isKindOfClass: [UITextField class] = NO ){
Continue;
}
If ([textField isFirstResponder]) {
IndexPathOfOwnerCell = indexPath;
NSLog (@ "indexPath. section = % d", indexPath. section );
NSLog (@ "indexPath. row = % d", indexPath. row );
Break;
}
}

[UIView commitAnimations];

If (indexPathOfOwnerCell! = Nil ){
[Self. myTableView scrollToRowAtIndexPath: indexPathOfOwnerCell
AtScrollPosition: UITableViewScrollPositionMiddle
Animated: YES];
}
</Pre> <br>
<Pre> </pre>
<Br>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.