如何在tableView的数据源和代理事件之外获取当前点击的是哪一行
来源:未知 责任编辑:责任编辑 发表时间:2013-11-15 19:49 点击:次
[cpp] view plaincopy
<pre name="code" class="cpp"> NSIndexPath *indexPathOfOwnerCell = nil;
/* Also, make sure the selected text field is visible on the screen */
//获取每个section里共有多少个cell
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 of
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
<pre name="code" class="cpp"> NSIndexPath *indexPathOfOwnerCell = nil;
/* Also, make sure the selected text field is visible on the screen */
//获取每个section里共有多少个cell
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 of
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
相关新闻>>
- IOS详解TableView——内置刷新,EGO,以及搜索显示控制器
- iOS UITableViewCell透明度 和 cell文字居中
- UITableView 分页显示、加载更多,数据源远程数据,解析JSON,以
- IOS开发之TableView替换默认的checkmark为自定义图像
- IOS开发之tableview只选中一行
- ios UITableView实现单击提示,滑动删除,多选行等操作
- ios 关于UITableView UITableViewCellAccessoryCheckmark 混乱的
- Iphone自定义UITableViewCell
- iphone练习之TableView
- UITableView一些方法
- 发表评论
-
- 最新评论 更多>>