Ios group buying category page (9 gongge), ios category page
=-= Some naming errors, but the functions are implemented. Pay attention to the naming rules later.
WJViewGroup. h
# Import <UIKit/UIKit. h> @ interface WJViewGroup: UIView {NSInteger _ width; NSInteger _ height;} @ property (nonatomic, assign) NSInteger widthNum; // number of rows @ property (nonatomic, assign) NSInteger heightNum; // Number of bars @ property (copy, nonatomic) void (^ itemBlock) (NSInteger index); // click the callback @ property (nonatomic, assign) BOOL isLine; @ property (nonatomic, strong) NSMutableArray * array; /*** add item ** @ param widthItem high quantity * @ param heightItem wide quantity * @ param num number of items */-(void) addItem :( NSInteger) widthItem :( NSInteger) heightItem num :( NSArray *) num;/*** change the item text ** @ param array text array */-(void) item :( NSArray *) array; @ end
WJViewGroup. m
# Import "WJViewGroup. h "@ implementation WJViewGroup-(instancetype) initWithFrame :( CGRect) frame {self = [super initWithFrame: frame]; if (self) {_ width = frame. size. width; self. backgroundColor = [UIColor whiteColor]; _ height = frame. size. height; self. layer. borderWidth = 1; self. clipsToBounds = YES; self. layer. cornerRadius = 5; _ widthNum = 3; _ heightNum = 3; _ array = [[NSMutableArray alloc] init];} return self ;} # pragma mark-add item 3 rows ---------- (void) addItem :( NSInteger) widthItem :( NSInteger) heightItem num :( NSArray *) num {NSInteger index = 0; NSInteger indeNume = 0; for (NSInteger I = 0; I <widthItem; I ++) {NSInteger index_Y = 0; for (NSInteger j = 0; j
Usage:
1. directly use
WJViewGroup * group = [[WJViewGroup alloc] initWithFrame: CGRectMake (ScreenWidth * 0.05, 20, ScreenWidth * 0.9, 120)]; group. isLine = YES; group. layer. borderColor = [UIColor colorWithHexString: @ "d3d1d1"]. CGColor; [group addItem: 3 widthItem: 3 num: @ [@ "food", @ "movie", @ "KTV", @ "Lobster", @ "dessert ", @ "seafood", @ "hot pot", @ "buffet", @ "Vegetables"]; [group setItemBlock: ^ (NSInteger index) {NSLog (@ "% ld ", index) ;}]; [self. view addSubview: group];
:
2. Use in cell
Custom cell Initialization
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier cellHeight:(NSInteger)cellHeight;
_group = [[WJViewGroup alloc]initWithFrame:CGRectMake(ScreenWidth*0.05, CGRectGetHeight(viewBG.frame) +5, ScreenWidth*0.9, cellHeight)]; _group.isLine = YES; if (cellHeight == 80) { _group.heightNum = 2; } _group.layer.borderColor = [UIColor colorWithHexString:@"d3d1d1"].CGColor; [_group addItem:3 widthItem:3 num:@[@"",@"",@"",@"",@"",@"",@"",@"",@""]]; [self.contentView addSubview:_group];
Lazy loading:
-(NSArray *) arrayContext {if (! _ ArrayContext) {_ arrayContext = [[NSArray alloc] initWithObjects: @ [@ "hot pot", @ "cake dessert", @ "Western food", @ "buffet ", @ "snacks and fast food", @ "Toy cooked fish", @ "dinner banquet", @ "barbecue", @ "Japanese and Korean cuisine"], @ [@ "budget hotel ", @ "luxury hotel", @ "theme hotel", @ "apartment hotel", @ "Inn", @ "youth hostel"], @ [@ "Hairdressing ", @ "manicure", @ "Beauty and body", @ "yoga/dance"], @ [@ "", @ "Aquarium", @ "Exhibition Hall ", @ "dynamic Botanical Garden", @ "theme park", @ "Water Park"], @ [@ "performance events", @ "table games/video games", @ "sports and fitness ", @ "Pedicure massage", @ "bath/steam", @ "4D/5D movie",], nil];} return _ arrayContext ;}
Proxy method:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
[cell.group item:self.arrayContext[indexPath.row]]; [cell.group setItemBlock:^(NSInteger index) { NSLog(@"%ld",index); }];
: