Skip to content

Instantly share code, notes, and snippets.

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let rawValue = indexPath.section*100 + indexPath.row
switch TableIndex(rawValue: rawValue) {
case .a:
// do something
case .b:
// do something
}
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
switch indexPath {
case TableIndex.a:
// do something
case TableIndex.b:
// do something
}
}
#if !DEBUG
public func print(_ items: Any..., separator: String = " ", terminator: String = "\n") { }
#endif
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
if #available(iOS 15.0, *){
let appearance = UINavigationBarAppearance()
appearance.configureWithOpaqueBackground()
appearance.backgroundColor = UIColor(red: 0.0/255.0, green: 125/255.0, blue: 0.0/255.0, alpha: 1.0)
appearance.titleTextAttributes = [.foregroundColor: UIColor.white]
ini_set("max_execution_time", "300");
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell: UITableViewCell = tableView.dequeueReusableCell(withIdentifier: "cell") ?? UITableViewCell(style: .value2, reuseIdentifier: "cell")
cell.textLabel?.text = "left"
cell.detailTextLabel?.text = "right"
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell: UITableViewCell = tableView.dequeueReusableCell(withIdentifier: "cell") ?? UITableViewCell(style: .value1, reuseIdentifier: "cell")
cell.textLabel?.text = "left"
cell.detailTextLabel?.text = "right"
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell: UITableViewCell = tableView.dequeueReusableCell(withIdentifier: "cell") ?? UITableViewCell(style: .subtitle, reuseIdentifier: "cell")
cell.imageView?.image = UIImage(named: "2")
cell.textLabel?.text = "title"
cell.detailTextLabel?.text = "subTitle"
}
private func setWebView(_ data: String){
let jscript = "var meta = document.createElement('meta'); meta.setAttribute('name', 'viewport'); meta.setAttribute('content', 'width=device-width'); document.getElementsByTagName('head')[0].appendChild(meta);"
let userScript = WKUserScript(source: jscript, injectionTime: .atDocumentEnd, forMainFrameOnly: true)
let wkUController = WKUserContentController()
wkUController.addUserScript(userScript)
let wkWebConfig = WKWebViewConfiguration()
wkWebConfig.userContentController = wkUController
let infoWebview = WKWebView(frame: self.contentView.bounds, configuration: wkWebConfig)
contentView.addSubview(infoWebview)
let index = IndexPath(row: 4, section: 0)
if tableView.cellForRow(at: index) != nil {
tableView.reloadRows(at: index, with: .automatic)
}