Sag*_* In 38 uitableview uisplitviewcontroller ios
嗨,我有一个情况,在iPad应用程序我的master controller列表和细节控制器有其细节,一个典型的UISplitViewController模式.我想要实现的是,我的第一行应该是最初选择的,之后我想给用户选择选择.我正在使用单元格setSelected和didSelectRowAtIndexPath方法删除这样的选择.
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:NO];
NSIndexPath* path = [NSIndexPath indexPathForRow:0 inSection:0];
UITableViewCell* cell = [tableView cellForRowAtIndexPath:path];
[cell setSelected:NO];
}
Run Code Online (Sandbox Code Playgroud)
对于初始细胞,但我的无细胞被选中后请帮助我.
Dre*_*w C 83
要使单元格显示为已选中,您必须-setSelected:animated:从内部调用,-tableView:willDisplayCell:forRowAtIndexPath:如下所示:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (/* should be selected */) {
[cell setSelected:YES animated:NO];
}
}
Run Code Online (Sandbox Code Playgroud)
-setSelected从其他任何地方打电话都没有效果.
Rav*_*ran 55
试试这个
NSIndexPath* selectedCellIndexPath= [NSIndexPath indexPathForRow:0 inSection:0];
[self tableView:tableViewList didSelectRowAtIndexPath:selectedCellIndexPath];
[tableViewList selectRowAtIndexPath:selectedCellIndexPath animated:YES scrollPosition:UITableViewScrollPositionNone];
Run Code Online (Sandbox Code Playgroud)
要么
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (/* should be selected */) {
[cell setSelected:YES animated:NO];
}
}
Run Code Online (Sandbox Code Playgroud)
Pet*_*inz 40
Swift 4:最初选择单元格
import UIKit
class MyViewController: UIViewController, UITableViewDelegate {
@IBOutlet weak var tableView: UITableView!
...
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
if /* your code here */ == indexPath.row {
tableView.selectRow(at: indexPath, animated: false, scrollPosition: UITableView.ScrollPosition.none)
}
}
...
}
Run Code Online (Sandbox Code Playgroud)
小智 10
我不知道你期待这个答案.默认情况下,如果要在没有手动选择的情况下选择tableView中的第一行,只需启动这样的didSelectRowAtIndexPath方法即可
- (void)viewDidAppear:(BOOL)animated {
NSIndexPath *indexPath=[NSIndexPath indexPathForRow:0 inSection:0];
[myTableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionBottom];
}
Run Code Online (Sandbox Code Playgroud)
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
if shouldSelectThisRow {
tableView.selectRow(at: indexPath, animated: false, scrollPosition: .none)
} else {
tableView.deselectRow(at: indexPath, animated: false)
}
}
Run Code Online (Sandbox Code Playgroud)
它也将有助于POP导航
.h文件,
NSIndexPath *defaultSelectedCell
Run Code Online (Sandbox Code Playgroud)
.m文件
把这段代码放进去 ViewDidLoad
defaultSelectedCell= [NSIndexPath indexPathForRow:0 inSection:0];
Run Code Online (Sandbox Code Playgroud)
在 viewDidAppear
[self.tableView selectRowAtIndexPath:defaultSelectedCell animated:NO scrollPosition:UITableViewScrollPositionNone];
Run Code Online (Sandbox Code Playgroud)
这将有助于POP,将此代码放入 viewWillAppear
[self.catTableView selectRowAtIndexPath:defaultSelectedCell animated:NO scrollPosition:UITableViewScrollPositionNone];
Run Code Online (Sandbox Code Playgroud)
在tableView didSelectRowAtIndexPath方法中,
defaultSelectedCell = [NSIndexPath indexPathForRow:indexPath.row inSection:0];
Run Code Online (Sandbox Code Playgroud)
这有助于我第一次加载或弹出导航.
| 归档时间: |
|
| 查看次数: |
51437 次 |
| 最近记录: |