您必须执行其他操作才能使行不突出显示。我只是试了一下,通过 Storyboard UIContainerView 和手动加载和添加“包含”视图“自动化”它。也使用 Swift 和 Objective-C UITableViewController 类。
按预期突出显示和未突出显示的点击行。
//
// ManualContainerViewController.swift
//
import UIKit
class ManualContainerViewController: UIViewController {
@IBOutlet weak var containerView: UIView!
override func viewDidLoad() {
super.viewDidLoad()
if true {
//use swift table view controller
if let childViewController = storyboard?.instantiateViewController(withIdentifier: "containedTableVC") as? ContainedTableViewController {
guard let childView = childViewController.view else { return }
addChildViewController(childViewController)
containerView.addSubview(childView)
childView.translatesAutoresizingMaskIntoConstraints = false
childView.leadingAnchor.constraint(equalTo: containerView.leadingAnchor, constant: 0.0).isActive = true
childView.trailingAnchor.constraint(equalTo: containerView.trailingAnchor, constant: 0.0).isActive = true
childView.topAnchor.constraint(equalTo: containerView.topAnchor, constant: 0.0).isActive = true
childView.bottomAnchor.constraint(equalTo: containerView.bottomAnchor, constant: 0.0).isActive = true
childViewController.didMove(toParentViewController: self)
}
} else {
// use Objective-C table view controller
if let childViewController = storyboard?.instantiateViewController(withIdentifier: "oc_containedTableVC") as? OCContainedTableViewController {
guard let childView = childViewController.view else { return }
addChildViewController(childViewController)
containerView.addSubview(childView)
childView.translatesAutoresizingMaskIntoConstraints = false
childView.leadingAnchor.constraint(equalTo: containerView.leadingAnchor, constant: 0.0).isActive = true
childView.trailingAnchor.constraint(equalTo: containerView.trailingAnchor, constant: 0.0).isActive = true
childView.topAnchor.constraint(equalTo: containerView.topAnchor, constant: 0.0).isActive = true
childView.bottomAnchor.constraint(equalTo: containerView.bottomAnchor, constant: 0.0).isActive = true
childViewController.didMove(toParentViewController: self)
}
}
}
}
//
// ContainedTableViewController.swift
//
import UIKit
class ContainedTableViewController: UITableViewController {
override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 30
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "basicCell", for: indexPath)
cell.textLabel?.text = "\(indexPath)"
return cell
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
}
}
//
// OCContainedTableViewController.h
//
#import <UIKit/UIKit.h>
@interface OCContainedTableViewController : UITableViewController
@end
//
// OCContainedTableViewController.m
//
#import "OCContainedTableViewController.h"
@interface OCContainedTableViewController ()
@end
@implementation OCContainedTableViewController
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 30;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"oc_basicCell" forIndexPath:indexPath];
cell.textLabel.text = [NSString stringWithFormat:@"Section: %ld / Row: %ld", (long)indexPath.section, (long)indexPath.row];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
@end