To run the demo project, clone the repo, and run pod install
from the Example directory first.
JUNTableView is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'JUNTableView'
#import <JUNTableView/UITableView+JUNex.h>
into your project's pch file, otherwise you will need to import this header in anywhere you want to quickly create a tableview.- There are a couple of methods that you can use to create a tableview quickly and elegantly.
+ (instancetype)jun_tableViewWithItems:(NSArray<UIView *> *)items;
+ (instancetype)jun_tableViewWithItemsBuilder:(JUNTableViewItemsBuilder)itemsBuilder;
+ (instancetype)jun_tableViewWithItemCount:(NSUInteger)itemCount itemBuilder:(JUNTableViewItemIndexBuilder)itemBuilder;
+ (instancetype)jun_tableViewWithItemCountBuilder:(JUNTableViewCountBuilder)countBuilder itemBuilder:(JUNTableViewItemIndexBuilder)itemBuilder;
+ (instancetype)jun_tableViewWithForEach:(NSArray<id> *)elements itemBuilder:(JUNTableViewItemForEachBuilder)itemBuilder;
Don't worry about not specifying some of the parameter types in these methods, when you type these methods in XCode, you'll immediately know what to do next. 3. Here are some examples.
[UITableView jun_tableViewWithItems:@[
aUILabel,
aUIButton,
aUISwitch,
...
]];
[UITableView jun_tableViewWithForEach:aStringArray
itemBuilder:^UIView *(NSUInteger index, id element) {
if ([element isEqual:@"text"]) {
return aUILabel;
} else if ([element isEqual:@"button"]) {
return aUIButton;
} else {
// Fall on other conditions...
}
}];
UITableView *tableview = [UITableView jun_tableViewWithItemCountBuilder:^NSUInteger{
return getRandomInteger();
} itemBuilder:^UIView *(NSUInteger index) {
if (index == 0) {
return aUILabel,
} else {
// Fall on other conditions...
}
}];
[NSTimer scheduledTimerWithTimeInterval:1.0 repeats:true block:^(NSTimer *timer) {
[tableview reloadData];
}];
- A created tableview can set the delegate and datasource as normal.
tableview.delegate = anyDelegate;
tableview.dataSouce = anyDataSource;
- Tableview created by the above methods has some additional properties.
@property(nonatomic, assign) JUNTableViewItemAlignment jun_alignment;
@property(nonatomic, assign) CGFloat jun_itemSpacing;
@property(nonatomic, assign) CGFloat jun_indent;
You can go to <JUNTableView/UITableView+JUNex.h>
to see in detail.
Jun Ma, [email protected]
JUNTableView is available under the MIT license. See the LICENSE file for more info.