Giter Site home page Giter Site logo

bcylin / quicktableviewcontroller Goto Github PK

View Code? Open in Web Editor NEW
555.0 12.0 66.0 1.7 MB

A simple way to create a UITableView for settings in Swift.

Home Page: https://bcylin.github.io/QuickTableViewController

License: MIT License

Swift 97.23% Ruby 1.02% Objective-C 0.80% Makefile 0.81% Shell 0.14%
swift ios tableview settings switch-control radio-buttons

quicktableviewcontroller's Introduction

QuickTableViewController

GitHub Actions Codecov Carthage compatible CocoaPods Compatible Platform Swift 5

A simple way to create a table view for settings.

Sunsetting

ℹ️ If your deployment target is iOS 13 or above, please consider using SwiftUI.

QuickTableViewController was designed to show static table contents when it was around iOS 8 and Swift 1.2. Over the past few iterations, a couple more controls were added but it still has its limitations. After the introduction of List and Form in iOS 13, SwiftUI has become a better solution for both static and dynamic table views.

QuickTableViewController will stay at the latest released version v1.3.1 from now on. Future updates will be mostly experimental. To use QuickTableViewController in UIKit, please see:

SwiftUI

The same settings layout can be implemented in SwiftUI and integrated into UIKit using UIHostingController. For more, please see Example-iOS/SwiftUI.

var body: some View {
    Form {
        Section(header: Text("Switch")) {
            Toggle(isOn: $viewModel.flag1) {
                subtitleCellStyle(title: "Setting 1", subtitle: "Example subtitle")
                    .leadingIcon("globe")
            }
            Toggle(isOn: $viewModel.flag2) {
                subtitleCellStyle(title: "Setting 2", subtitle: nil)
                    .leadingIcon("clock.arrow.circlepath")
            }
        }

        Section(header: Text("Tap Action")) {
            Button {
                viewModel.performTapAction()
            } label: {
                Text("Tap action").frame(maxWidth: .infinity)
            }
        }

        Section(header: Text("Cell Style"), footer: Text("CellStyle.value2 is not implemented")) {
            subtitleCellStyle(title: "CellStyle.default", subtitle: nil)
                .leadingIcon("gear")
            subtitleCellStyle(title: "CellStyle.default", subtitle: ".subtitle")
                .leadingIcon("globe")
            value1CellStyle(title: "CellStyle", detailText: ".value1")
                .leadingIcon("clock.arrow.circlepath")
                .navigationFlow { viewModel.startNavigationFlow() }
        }

        Section(header: Text("Radio Button")) {
            ForEach(SettingsViewModel.Option.allCases) { option in
                checkmarkCellStyle(with: option, isSelected: viewModel.isOptionSelected(option))
            }
        }
    }
}

License

QuickTableViewController is released under the MIT license. Image source: iconmonstr

quicktableviewcontroller's People

Contributors

bcylin avatar czars avatar dependabot-preview[bot] avatar dependabot[bot] avatar dnicolson avatar drinkius avatar ezfe avatar fradeliro avatar getaaron avatar mttcrsp avatar sanekgusev avatar tobisaninfo avatar twodayslate avatar z3bi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

quicktableviewcontroller's Issues

[Help needed] Problems in changing underlying TableViewCell label

Thanks for this wonderful project first - seems to make life much easier!

I'd like to color the labels of QuickTableViewController's rows, but can't get it to work.

Though I'm able applying a general style in AppDelegate with...

  let tableViewCellLabelAppearance = UILabel.appearance(whenContainedInInstancesOf: [UITableViewCell.self])
  tableViewCellLabelAppearance.textColor = Theme.textColor

...all other labels in all other TableViewCells get colored accordingly, except of those from QuickTableViewController.

My naive approach to get this working was...

  let optionRowLabelAppearance = UILabel.appearance(whenContainedInInstancesOf: [OptionRow.self])
  optionRowLabelAppearance.textColor = Theme.textColor

...but this was refused with the compiler error message:

Cannot convert value of type 'OptionRow<UITableViewCell'>.Type to expected element type 'UIAppearanceContainerType'

Wondering now what the preferred way is theming QuickTableViewController views?

Thanks and best wishes,

Karsten

managing a value?

Is there any provision within this very helpful repo to manage a value? A small textbox of numeric input for example?

currently having this issue

-Swift.h:263:39: error: cannot find interface declaration for 'QuickTableViewController', superclass of
'IPSettingsViewController'; did you mean 'UITableViewController'?
@interface IPSettingsViewController : QuickTableViewController
^~~~~~~~~~~~~~~~~~~~~~~~
UITableViewController
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.2.sdk/System/Library/Frameworks/UIKit.framework/Headers/UITableViewController.h:20:49: note: 'UITableViewController'
declared here

How to make images fit into table cells properly

I want to add icons next to my settings items neatly like in the below screenshot. But at the moment, only the SF Symbols are in the correct size. When I add a custom image, it's always too big and tries to almost the entire height of the row. Is there an elegant way to do this? Please show an example.

IMG_9EAD7E82536F-1

TextFieldRow type?

Love the library.
Is there any plan to support something like a text field row?
Or am I missing something?

Unability to use the library in iOS12 project

I made a new project that goes from iOS12 to recent iOS14.2.
I import this library as Swift package, using version 1.2.3.

When I import this library in my class,
import QuickTableViewController

I get the following build error:
Compiling for iOS 12.4, but module 'QuickTableViewController' has a minimum deployment target of iOS 13.0: /Users/ME/Library/Developer/Xcode/DerivedData/MYAPP-goddzpszwntzcgakkvpsksjrjqsi/Build/Products/Debug-iphonesimulator/QuickTableViewController.swiftmodule/x86_64-apple-ios-simulator.swiftmodule.

I check the library's Package.swift, it supports iOS9 and up.
But then I noticed
swiftLanguageVersions: [.v5]

Could it be due to this line that library implicitly supports iOS13 and up, while defining the upper lines?

  platforms: [
        .iOS(.v9),
        .tvOS(.v9),
    ]

Thanks

How can I change selected and deselect accessoryView image?

As title, I was hoping to change the select and deselect image for my menu. However if I use original table view delegate "didSelect" and "deSelect" method, multi-selection section stop working.
Is there a proper way to change it. Thx

Passing true to the switch value is not working

As you can see I'm passing true value to the switch but it is not showing in the app it is on

Section(title: "App Settings", rows: [
                SwitchRow<SwitchCell>(title: "Push notifications", switchValue: true, icon: Icon(image: notification), action: weakify(self, type(of: self).didTogglePushNotification)),
                
                SwitchRow<SwitchCell>(title: "Enable touch ID", switchValue: isTouchIdenable, icon: Icon(image: touchid), action: weakify(self, type(of: self).didToggleTouchId))
                ])

How to change text color

I want to change the text color of a NavigationRow to be red to represent a destructive action such as deleting all data.

Feature Request: Making rows more scalable

I was thinking about how I can introduce more custom types of rows without modifying too much of the source code. I came up with something different..

What if the Row protocol had a method to generate it's own UITableViewCell. That way the logic for the row generation is in the object and not the QuickTableViewController.

example:

extension Row {
    
    /// Return a customized cell for the table
    public func tableCell() -> UITableViewCell {
        return UITableViewCell()
    }
    
}

I want to make a row that allows selection. Essentially a NavigationRow with the option to change the accessoryType.

My first idea might just be nonsense... It might just be easier to add a accessoryType variable to navigation row, and have the view controller check if the accessory type is set. Ideally I want to just view a checkmark... See attached image.. Thoughts?

check

Update:

Take a look at this commit I made. It has a few major changes. I don't have pods installed so I removed those files. I also don't think the master framework would want to use any pods, but I could be wrong..

3D Touch

This is a feature request for being able to peek/pop on a TapActionCell cell that presents something modally to be able to "preview" the view controller

How to reload the settings menu

Hi, I need to be able to programatically reload the settings view for two reasons:

  • some users are confused after they upgrade to premium that the menu still has options disabled as though they are not premium users
  • I have using this NavigationRow(text: "CellStyle", detailText: .value2(".value2")) and after a user selects a new option for .value2 I want my settings menu to display the new value instead of the initial one loaded at app launch

Is it possible to reload the menu? Thanks.

LinkCell / LinkRow

This is a feature request for LinkCell and LinkRow to mimic the links sometimes used in the iOS Settings app.

image

Why is subtitle disabled in `OptionRow`?

OptionRow.swift:

  /// Subtitle is disabled in `OptionRow`.
  public let subtitle: Subtitle? = nil

Why? Is this a technical limitation, or is this something we could work on adding?

heightForRowAt function

Please override heightForRowAt method in this library. Because right now, I have to manually override this function everytime.
Thank you

random cell being highlighted

This is on tvOS

I have a cell that when clicked on, shows an alert where the user can select from a series of options.

When the user clicks on an option and the alert is dismissed, the cell that the user clicked on is no longer highlighted, a random one is highlighted instead. Is there anyway this can be fixed please?

Convert Testing Targets to Swift 4.2

There are two testing bundles yet updated to Swift 4.2:

QuickTableViewController-iOSTests

PRODUCT_NAME = QuickTableViewControllerTests;
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;

QuickTableViewController-tvOSTests

PRODUCT_NAME = QuickTableViewControllerTests;
SDKROOT = appletvos;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_VERSION = 4.0;

Missing subtitles with multiple SwitchRow elements

When using multiple SwitchRow elements, subtitles can be hidden at random.

In the following example the "Setting14" row is missing the subtitle:

Screen Shot 2020-06-25 at 18 28 42

This has been tested in the following environments:
Xcode 11.3.1 (11C504) on macOS 10.14.6 (18G3020)
Xcode 11.5 (11E608c) on macOS 11.0 Beta (20A4299v)

This looks like it may be an Apple bug as the behaviour is somewhat erratic.

Any option to mount the tableview to a UIView?

If I want to place the table view at a specific spot, how can I do that?

I currently kinda just hack it by adding a parentView open var in QuickTableViewController. Then I have the option to set the parentView.

// viewDidLoad
parentView = parentView ?? view
parentView?.addSubview(tableView)

Does this library already provide a way to do it that I just didn't know?

How to disable a setting option

Hi, I have just started using QuickTableViewController to create a settings tab for my iOS app. One of my settings (a toggle switch) is only applicable to users that have the premium version. How do I disable the switch, grey it out or hide it until the user has upgraded to Premium? Thanks.

Update the icon property of a NavigationRow

Hi,

Is it possible to update the icon property of a NavigationRow with the option that was chosen in the view I navigated to?

This is my starting view, which has the action to push another view controller onto the stack. getCurrentAppIcon() in this view checks UIApplication.shared.alternateIconName and returns a named icon. The detail view just sets a new AlternateIcon. But I want the first view to show the newly chosen icon when I tap "< Back" in the nav bar.

Section(title: "App Icon", rows: [
    NavigationRow(
        text: "App Icon",
        detailText: .none,
        icon: getCurrentAppIcon(),
        action: { [weak self] _ in
        self?.navigationController?.pushViewController(SettingsAppIconViewController(), animated: true)
    })
]),

Thanks
Ben

SliderCell / SliderRow

This is a feature request for slider settings (like in brightness or text size) to manage a discrete value within a specific range

image

Possible to identify individual rows?

I'm wondering if there is a way currently with this library to allow for the identification of individual rows, for example in a case where you might have multiple navigation rows with the same style, but want to do something conditionally to each one. In my case, I am wanting to tint the icons of each row and hoping to not have to resort to creating pre-colored icon images for each different row. Normally you could use the reuse identifier to achieve something like this, but it seems like that is tied up here.

How to pass NavigationRow data and display in custom cell

Hi, I am doing some customization with NavigationRow. I wanna use the title, detailText, icon, parameters in my custom cell. However, when I set it in configure(), it always crash due to unwrap my cell properties.

Here's my code below. Thanks!

class GlobalInviteTVCell: UITableViewCell {

    @IBOutlet weak var mainTitle: UILabel!
    @IBOutlet weak var subTitle: UILabel!
    @IBOutlet weak var showImage: UIImageView!
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
}

extension GlobalInviteTVCell: Configurable {
    
    func configure(with row: Row & RowStyle) {
        self.mainTitle.text = row.text
        self.subTitle.text = row.detailText?.text
        self.showImage.image = row.icon?.image
    }
    
    
}

Is there a way to not auto toggle UISwitch on touch?

I am trying to link the UISwitch in SwitchRow to a bool value, but every time i click on the switch it toggles without checking the value in the init function.
Is there a way to change it in the action by accessing the Row parameter in the completion? i cannot find it!
Thanks!

How to get the modernUI with rounded corners? 🧐

First of all, thank you so much for this!

I was testing the Demo build and it has this modern UI with rounded corners — It looks pretty nice!

Simulator Screen Shot - iPad (8th generation) - 2021-06-18 at 02 24 19

but, after adding the dependency, I set the whole thing up (by adding tableContents in viewDidLoad) but I have this old UI with sharp corners

Simulator Screen Shot - iPad (8th generation) - 2021-06-18 at 02 24 28

I scratched my head for sometime and realized I might want to add this:

 init() {
    if #available(iOS 13.0, *) {
      super.init(style: .insetGrouped)
    } else {
      super.init(style: .grouped)
    }

    let titleLabel = UILabel()
    titleLabel.text = "QuickTableViewController"
    titleLabel.font = UIFont.boldSystemFont(ofSize: 17)
    title = " "
    navigationItem.titleView = titleLabel
  }

  required init?(coder: NSCoder) {
    fatalError("init(coder:) has not been implemented") }

because this was the only thing that was not in my code but it was present in demo build, but my app crashes with a Fatal Error init(coder:) has not been implemented

Thank you.

Switch

how to change Switch frame and color

` #if os(iOS)

/// A UISwitch as the accessoryView. Not available on tvOS.
@available(tvOS, unavailable, message: "switchControl is not available on tvOS.")
public private(set) lazy var switchControl: UISwitch = {
let control = UISwitch()
control.addTarget(self, action: #selector(SwitchCell.didToggleSwitch(_:)), for: .valueChanged)
return control
}()

#endif
`

how to change switchControl tintColor onTintColor frame ?

How to specify "alwaysSelectsOneOption" in RadioSection

Hi,

Forgive the noobie question, I am a beginner at Swift and iOS dev. Where do I specify the alwaysSelectsOneOption in RadioSection declaration? I can't find any examples in the source code or docs.

RadioSection(title: "Audio Quality", options: [
    OptionRow(
        text: "Medium",
        isSelected: userAudioQuality == "medium" ? true : false,
        action: didToggleQuality(quality: "medium")
    ),
    OptionRow(
        text: "High",
        isSelected: userAudioQuality == "high" ? true : false,
        action: didToggleQuality(quality: "high")
    ),
]),

Thanks,
Ben

How to set selectionStyle to none in NavigationRow

Hey,
how can I get rid of the the default selectionStyle. I don't want the cell to stay gray after clicking it.This may be something really trivial but I am a beginner in iOS.

let language = NavigationRow(text: "Language", detailText: .value1("Ελληνικά"), icon: .named("call"), action: { _ in })
    
    
tableContents = [
        Section(title: "App settings", rows: [
            language,
            NavigationRow(text: "UITableViewCell", detailText: .subtitle(".subtitle"), action: { _ in }),
            NavigationRow(text: "UITableViewCell2", detailText: .subtitle(".subtitle"), action: { _ in })
            
            ])
    ]

Visual Result:
Screenshot 2019-07-15 at 01 34 46

How to disable deselecting radio buttons?

I want to be able to make the radio buttons act like compulsory radio buttons where there is something selected. So if someone presses a button that is already selected, I don't want to select that row. How do I do this?

Reloading table stops animation

I've found when interacting with a SwitchRow that because it's telling the tableView to reload it's data, It stops the animation of the UIControl. You can really notice it when flipping a switch.

As a solution, I think it's best not to always reload the table just when you want to update the dataSource. It always updates because you implement the didSet of the source. Perhaps we give an option to perform a silent update? That way we can still update the source without forcing a redraw.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.