Skip to content

An extension to UITableView that makes creating tableviews efficiently and gracefully.

License

Notifications You must be signed in to change notification settings

Jun2786184671/JUNTableView

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JUNTableView

Version License Platform

Demo

To run the demo project, clone the repo, and run pod install from the Example directory first.

Installation

JUNTableView is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'JUNTableView'

Guide

  1. #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.
  2. 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];
}];
  1. A created tableview can set the delegate and datasource as normal.
tableview.delegate = anyDelegate;
tableview.dataSouce = anyDataSource;
  1. 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.

Author

Jun Ma, [email protected]

License

JUNTableView is available under the MIT license. See the LICENSE file for more info.

About

An extension to UITableView that makes creating tableviews efficiently and gracefully.

Resources

License

Stars

Watchers

Forks

Packages

No packages published