问题描述
我的UITableView通过PopOverViewController打开,所以如何在app加载后自动加载其中一个单元格,
My UITableView opens via PopOverViewController , so How can I load one of these cells automatically after app did load ,
MainViewController上的单元格选择过程
the cell selecting process on MainViewController
- (void)setDetailItem:(id)newDetailItem {
if (detailItem != newDetailItem) {
[detailItem release];
detailItem = [newDetailItem retain];
//---update the view---
label.text = [detailItem description];
}
}
并在TableViewController中选择单元格:
and cell selecting in TableViewController :
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
myAppDelegate *appDelegate =
[[UIApplication sharedApplication] delegate];
appDelegate.viewController.detailItem = [list objectAtIndex:indexPath.row];
}
我在TableViewController中使用此代码但不起作用!这意味着按下popOver按钮后代码只需突出显示单元格!
I use this code in TableViewController but does not work ! It means after press the the popOver button the code just highlight the cell !!
[myTableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:NO scrollPosition:0];
我在上面的代码中使用了不同的方法,例如 viewDidAppear
, viewWillAppear
和 didSelectRowAtIndexPath
和...
I used above code in different methods like viewDidAppear
, viewWillAppear
and didSelectRowAtIndexPath
and ...
谢谢
推荐答案
当你打电话给 selectRowAtIndexPath:animated:scrollPosition:
, tableView:didSelectRowAtIndexPath:
在委托上调用而不是。
When you call selectRowAtIndexPath:animated:scrollPosition:
, tableView:didSelectRowAtIndexPath:
is not called on the delegate.
来自 reference:
From the selectRowAtIndexPath:animated:scrollPosition: reference:
所以,不要只是调用 selectRowAtIndexPath:animated:scrollPosition:
:
[myTableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:NO scrollPosition:0];
您可以手动调用委托方法:
you could call the delegate methods manually:
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
if ([myTableView.delegate respondsToSelector:@selector(tableView:willSelectRowAtIndexPath:)]) {
[myTableView.delegate tableView:self.tableView willSelectRowAtIndexPath:indexPath];
}
[myTableView selectRowAtIndexPath:indexPath animated:YES scrollPosition: UITableViewScrollPositionNone];
if ([myTableView.delegate respondsToSelector:@selector(tableView:didSelectRowAtIndexPath:)]) {
[myTableView.delegate tableView:self.tableView didSelectRowAtIndexPath:indexPath];
}
这篇关于自动单元格选择UITableView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!