Skip to content
This repository has been archived by the owner on Aug 24, 2020. It is now read-only.

Commit

Permalink
3.0.0 release
Browse files Browse the repository at this point in the history
  • Loading branch information
davdroman committed Sep 27, 2015
1 parent 5a0a17b commit a778369
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 82 deletions.
Binary file modified Assets/1.gif
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed Assets/1.png
Binary file not shown.
Binary file removed Assets/2.png
Binary file not shown.
Binary file removed Assets/3.png
Binary file not shown.
Binary file removed Assets/4.png
Binary file not shown.
Binary file removed Assets/5.png
Binary file not shown.
Binary file removed Assets/6.png
Binary file not shown.
2 changes: 1 addition & 1 deletion Bohr.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "Bohr"
s.version = "3.0.0-rc.2"
s.version = "3.0.0"
s.summary = "Settings screen composing framework"
s.homepage = "https://github.com/DavdRoman/Bohr"
s.author = { "David Román" => "[email protected]" }
Expand Down
59 changes: 29 additions & 30 deletions Bohr/BOTableViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

@interface BOTableViewController ()

@property (nonatomic, copy) NSArray *lastSections;
@property (nonatomic) NSArray *sections;
@property (nonatomic) NSArray *footerViews;

Expand Down Expand Up @@ -150,21 +149,47 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
return cell;
}

- (void)reloadTableView {
- (void)tableView:(UITableView *)tableView willDisplayCell:(BOTableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
[cell _updateAppearance];
[cell updateAppearance];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
BOTableViewCell *cell = (BOTableViewCell *)[tableView cellForRowAtIndexPath:indexPath];

if ([cell expansionHeight] > 0) {
self.expansionIndexPath = ![indexPath isEqual:self.expansionIndexPath] ? indexPath : nil;

[self.tableView deselectRowAtIndexPath:indexPath animated:NO];
[self.tableView beginUpdates];
[self.tableView endUpdates];
[self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionMiddle animated:YES];
} else if (cell.destinationViewController) {
[self.navigationController pushViewController:cell.destinationViewController animated:YES];
} else if ([cell respondsToSelector:@selector(wasSelectedFromViewController:)]) {
[cell wasSelectedFromViewController:self];
}

if (cell.accessoryType != UITableViewCellAccessoryDisclosureIndicator) {
[self.tableView deselectRowAtIndexPath:indexPath animated:YES];
}
}

#pragma mark Dynamic options

- (void)reloadTableView {

NSMutableIndexSet *affectedIndexes = [NSMutableIndexSet new];

for (NSInteger s = 0; s < self.tableView.numberOfSections; s++) {
for (NSInteger s = 0; s < self.sections.count; s++) {
NSInteger numberOfRows = [self.tableView numberOfRowsInSection:s];

if (numberOfRows != [self.sections[s] cells].count) {
[affectedIndexes addIndex:s];
} else {
for (NSInteger r = 0; r < numberOfRows; r++) {
UITableViewCell *lastCell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:r inSection:s]];
if (![[self.sections[s] cells] containsObject:lastCell]) {
if ([self.tableView.visibleCells containsObject:lastCell] && ![[self.sections[s] cells] containsObject:lastCell]) {
[affectedIndexes addIndex:s];
}
}
Expand All @@ -185,32 +210,6 @@ - (void)reloadTableView {
}];
}

- (void)tableView:(UITableView *)tableView willDisplayCell:(BOTableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
[cell _updateAppearance];
[cell updateAppearance];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
BOTableViewCell *cell = (BOTableViewCell *)[tableView cellForRowAtIndexPath:indexPath];

if ([cell expansionHeight] > 0) {
self.expansionIndexPath = ![indexPath isEqual:self.expansionIndexPath] ? indexPath : nil;

[self.tableView deselectRowAtIndexPath:indexPath animated:NO];
[self.tableView beginUpdates];
[self.tableView endUpdates];
[self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionMiddle animated:YES];
} else if (cell.destinationViewController) {
[self.navigationController pushViewController:cell.destinationViewController animated:YES];
} else if ([cell respondsToSelector:@selector(wasSelectedFromViewController:)]) {
[cell wasSelectedFromViewController:self];
}

if (cell.accessoryType != UITableViewCellAccessoryDisclosureIndicator) {
[self.tableView deselectRowAtIndexPath:indexPath animated:YES];
}
}

#pragma mark Dynamic footers

- (NSArray *)footerViews {
Expand Down
2 changes: 1 addition & 1 deletion BohrDemo/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(

- (void)setupDefaults {
[[NSUserDefaults standardUserDefaults] registerDefaults:@{
@"bool_1": @YES,
@"bool_1": @NO,
@"bool_2": @NO,
@"text": @"",
@"number": @0,
Expand Down
4 changes: 2 additions & 2 deletions BohrDemo/TableViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ - (void)setup {

[section addCell:[BOSwitchTableViewCell cellWithTitle:@"Switch 1" key:@"bool_1" handler:nil]];

[section addCell:[BOSwitchTableViewCell cellWithTitle:@"Switch 2 (dependant on switch 1)" key:@"bool_2" handler:^(BOSwitchTableViewCell *cell) {
[section addCell:[BOSwitchTableViewCell cellWithTitle:@"Switch 2" key:@"bool_2" handler:^(BOSwitchTableViewCell *cell) {
cell.visibilityKey = @"bool_1";
cell.visibilityBlock = ^BOOL(id settingValue) {
return [settingValue boolValue];
Expand All @@ -37,7 +37,7 @@ - (void)setup {
[weakSelf showInputErrorAlert:error];
};
}]];

[section addCell:[BONumberTableViewCell cellWithTitle:@"Number" key:@"number" handler:^(BONumberTableViewCell *cell) {
cell.textField.placeholder = @"Enter number";
cell.numberOfDecimals = 3;
Expand Down
63 changes: 15 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,49 +38,27 @@ Drag and copy all files in the [__Bohr__](Bohr) folder into your project.

#### Basic setup

The settings screen you're going to set up is represented by a `UITableViewController` subclass called `BOTableViewController`.
The settings screen you're going to set up is represented by a `UITableViewController` subclass called `BOTableViewController`. Such controller manages `BOTableViewSection` instances, and each one of those manages a set of `BOTableViewCell` instances.

<p align="center">
<img src="Assets/1.png" alt="PNG 1" />
</p>

Set the `UITableViewController` class to `BOTableViewController` or a subclass of it.

<p align="center">
<img src="Assets/2.png" alt="PNG 2" />
</p>

Make sure to make the `UITableView` static and (optionally) grouped.

<p align="center">
<img src="Assets/3.png" alt="PNG 3" />
</p>

Set each cell class to the desired `BOTableViewCell` subclass.

<p align="center">
<img src="Assets/4.png" alt="PNG 4" />
</p>

Set each cell style to detail. Sometimes basic style is enough to make it work since not every cell needs a detail label, but in case of doubt detail style will work just fine.

<p align="center">
<img src="Assets/5.png" alt="PNG 5" />
</p>
Here's an example of a really simple setup included in the demo project. Please check it out to see the full implementation. Please notice the code below belongs inside the `setup` method of a subclassed `BOTableViewController`.

Finally, set the key of the cell to the desired value.

<p align="center">
<img src="Assets/6.png" alt="PNG 6" width="260" />
</p>
```obj-c
- (void)setup {
[self addSection:[BOTableViewSection sectionWithHeaderTitle:@"Section 1" handler:^(BOTableViewSection *section) {
[section addCell:[BOSwitchTableViewCell cellWithTitle:@"Switch 1" key:@"bool_1" handler:nil]];
}]];
}
```

#### Built-in BOTableViewCell's

As mentioned before, there's a bunch of built-in `BOTableViewCell` subclasses ready to be used:
There's a bunch of built-in `BOTableViewCell` subclasses ready to be used:

- `BOSwitchTableViewCell`: manages `BOOL` values through a `UISwitch` control.
- `BOTextTableViewCell`: manages `NSString` values through a `UITextField` control.
- `BOTimeTableViewCell`: manages `NSInteger` values that represent a given time as the minute interval from midnight to such time. A revealing `UIPickerView` is used to set the time.
- `BONumberTableViewCell`: manages `NSNumber` values through a `UITextField` control.
- `BODateTableViewCell`: manages `NSDate` values representing a certain date. A revealing `UIDatePicker` is used to set the time.
- `BOTimeTableViewCell`: manages `NSDate` values representing a certain time. A revealing `UIDatePicker` is used to set the time.
- `BOChoiceTableViewCell`: manages `NSInteger` values (which you can understand as "options" from a `NS_ENUM`) through taps on the cell itself.
- `BOOptionTableViewCell`: manages a single `NSInteger` value (which you can understand as an "option" from a `NS_ENUM`) depending on its position in its table view section. When selected, a checkmark appears on the right side.
- `BOButtonTableViewCell`: allows the user to perform an action when the cell is tapped.
Expand All @@ -95,20 +73,9 @@ First of all, the framework contains a header file called `BOTableViewCell+Subcl
#import <Bohr/BOTableViewCell+Subclass.h>
```

That way you'll be able to access all the necessary methods for you to implement in your subclass:

- `setup`: used to set up the cell for the first time.
- `updateAppearance`: any code that defines the appearance of the cell should be put here. Note every `BOTableViewCell` instance contains 4 properties used to define its style:
- `mainColor`: the color used for the title and other main elements of the cell.
- `mainFont`: the font used for the title and other main elements of the cell.
- `secondaryColor`: the color used for the detail text and other secondary elements of the cell.
- `secondaryFont`: the font used for the detail text and other secondary elements of the cell.
- `expansionHeight`: the cell height will be expanded to the value returned by this method when tapped.
- `footerTitle`: the footer text to be displayed as a result of a setting value being modified.
- `wasSelectedFromViewController:`: called when the cell is tapped. The `BOTableViewController` where the cell is contained is passed.
- `settingValueDidChange`: called when the `NSUserDefault` value associated with the cell changes. You must represent such change through some visual element on your cell. Accessing that new value is as simple as calling `self.setting.value`.
That way you'll be able to access all the possible elements for you to implement in your subclass.

Please take a look to the implementation of `BOSwitchTableViewCell` for a more detailed demonstration on how to subclass `BOTableViewCell`.
Please take a look to some of the built-in cells for a more detailed demonstration on how to subclass `BOTableViewCell`.

## License

Expand Down

0 comments on commit a778369

Please sign in to comment.