AppDelegate.m
#import "AppDelegate.h"
#import "ViewController.h"
#import "SecondViewController.h"
#import "ThirdViewController.h"
#import "FourViewController.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
? ? // Override point for customization after application launch.
? ? ViewController *v1 = [[ViewController alloc]init];
? ? UINavigationController *nav1 = [[UINavigationController alloc]initWithRootViewController:v1];
? ? UITabBarItem *item1 = [[UITabBarItem alloc]initWithTitle:@"外賣" image:[UIImage imageNamed:@"menu_ico_shop_26x26_@3x"] selectedImage:[UIImage imageNamed:@"menu_ico_shop_on_26x26_@3x"]];
? ? nav1.tabBarItem = item1;
? ? SecondViewController *s1 = [[SecondViewController alloc]init];
? ? UINavigationController *nav2 = [[UINavigationController alloc]initWithRootViewController:s1];
? ? UITabBarItem *item2 = [[UITabBarItem alloc]initWithTitle:@"發(fā)現(xiàn)" image:[UIImage imageNamed:@"menu_ico_gather_26x26_@3x"] selectedImage:[UIImage imageNamed:@"menu_ico_gather_on_26x26_@3x"]];
? ? nav2.tabBarItem = item2;
? ? ThirdViewController *t1 = [[ThirdViewController alloc]init];
? ? UINavigationController *nav3 = [[UINavigationController alloc]initWithRootViewController:t1];
? ? UITabBarItem *item3 = [[UITabBarItem alloc]initWithTitle:@"訂單" image:[UIImage imageNamed:@"ico_share_wechat_26x26_@3x"] selectedImage:[UIImage imageNamed:@"ico_share_wechat_on_26x26_@3x"]];
? ? nav3.tabBarItem = item3;
? ? FourViewController *f1 = [[FourViewController alloc]init];
? ? UINavigationController *nav4 = [[UINavigationController alloc]initWithRootViewController:f1];
? ? UITabBarItem *item4 = [[UITabBarItem alloc]initWithTitle:@"我的" image:[UIImage imageNamed:@"menu_ico_center_26x26_@3x"] selectedImage:[UIImage imageNamed:@"menu_ico_center_on_26x26_@3x"]];
? ? nav4.tabBarItem = item4;
? ? UITabBarController *tabbar = [[UITabBarController alloc]init];
? ? tabbar.viewControllers = @[nav1,nav2,nav3,nav4];
? ? self.window.rootViewController = tabbar;
? ? return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application {
? ? // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
? ? // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}
- (void)applicationDidEnterBackground:(UIApplication *)application {
? ? // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
? ? // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
- (void)applicationWillEnterForeground:(UIApplication *)application {
? ? // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
? ? // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
- (void)applicationWillTerminate:(UIApplication *)application {
? ? // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
@end
TwoBtn.m
#import "TwoBtn.h"
@implementation TwoBtn
//調(diào)整title的位置
- (CGRect)titleRectForContentRect:(CGRect)contentRect
{
? ? CGRect rect;
? ? CGFloat titleW = contentRect.size.width;
? ? CGFloat titleH = 20;
? ? CGFloat titleX = 10;
? ? CGFloat titleY = 60;
? ? rect = CGRectMake(titleX, titleY, titleW, titleH);
? ? return rect;
}
//調(diào)整image的位置
- (CGRect)imageRectForContentRect:(CGRect)contentRect
{
? ? CGRect rect;
? ? CGFloat imageW = 50;
? ? CGFloat imageH = 50;
? ? CGFloat imageX = 15;
? ? CGFloat imageY = 0;
? ? rect = CGRectMake(imageX, imageY, imageW, imageH);
? ? return rect;
}
@end
MyButton.m
#import "MyButton.h"
@implementation MyButton
//調(diào)整title的位置
- (CGRect)titleRectForContentRect:(CGRect)contentRect
{
? ? CGRect rect;
? ? CGFloat titleW = 100;
? ? CGFloat titleH = 30;
? ? CGFloat titleX = 10;
? ? CGFloat titleY = 15;
? ? rect = CGRectMake(titleX, titleY, titleW, titleH);
? ? return rect;
}
//調(diào)整image的位置
- (CGRect)imageRectForContentRect:(CGRect)contentRect
{
? ? CGRect rect;
? ? CGFloat imageW = 50;
? ? CGFloat imageH = 50;
? ? CGFloat imageX = 130;
? ? CGFloat imageY = 8;
? ? rect = CGRectMake(imageX, imageY, imageW, imageH);
? ? return rect;
}
@end
OneTableViewCell.m
#import "OneTableViewCell.h"
@implementation OneTableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
? ? if (self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
? ? ? ? [self CustomUi];
? ? }
? ? return self;
}
- (void)CustomUi
{
? ? UIView *views = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 414, 180)];
? ? views.backgroundColor = [UIColor colorWithRed:27/255.0 green:154/255.0 blue:252/255.0 alpha:1.0];
? ? [self.contentView addSubview:views];
? ? UILabel *labels = [[UILabel alloc]initWithFrame:CGRectMake(10, 20, 200, 50)];
? ? labels.text = @"餓了就要餓了么";
? ? labels.textColor = [UIColor whiteColor];
? ? labels.font = [UIFont systemFontOfSize:28 weight:2.0];
? ? [views addSubview:labels];
? ? UILabel *labelss = [[UILabel alloc]initWithFrame:CGRectMake(350, 28, 30, 20)];
? ? labelss.textColor = [UIColor whiteColor];
? ? labelss.text = @"33°";
? ? labelss.font = [UIFont systemFontOfSize:13];
? ? [views addSubview:labelss];
? ? UILabel *labelsss = [[UILabel alloc]initWithFrame:CGRectMake(358, 41, 20, 20)];
? ? labelsss.textColor = [UIColor whiteColor];
? ? labelsss.text = @"陰";
? ? labelsss.font = [UIFont systemFontOfSize:11];
? ? [views addSubview:labelsss];
? ? UILabel *labelssss = [[UILabel alloc]initWithFrame:CGRectMake(380, 26, 40, 40)];
? ? labelssss.textColor = [UIColor whiteColor];
? ? labelssss.text = @"??";
? ? labelssss.font = [UIFont systemFontOfSize:15];
? ? [views addSubview:labelssss];
? ? UILabel *labelsT = [[UILabel alloc]initWithFrame:CGRectMake(10, 75, 200, 20)];
? ? labelsT.text = @"? 八維研修學(xué)院(第二校區(qū)) ▼";
? ? labelsT.textColor = [UIColor whiteColor];
? ? labelsT.font = [UIFont systemFontOfSize:13];
? ? [views addSubview:labelsT];
? ? UITextField *textF = [[UITextField alloc]initWithFrame:CGRectMake(8, 103, 398, 40)];
? ? textF.text = @"??輸入商家、商品名稱";
? ? textF.textAlignment = NSTextAlignmentCenter;
? ? textF.backgroundColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1.0];
? ? textF.textColor = [UIColor grayColor];
? ? textF.font = [UIFont systemFontOfSize:13];
? ? textF.layer.cornerRadius = 15;
? ? textF.layer.masksToBounds = YES;
? ? [views addSubview:textF];
? ? CGFloat width = 50;
? ? CGFloat X = 10;
? ? NSArray *array = [NSArray array];
? ? array = @[@"西瓜",@"醉唐軒",@"三元",@"加班食補(bǔ)",@"我的菜",@"紅燒肉",@"肯德基",@"慶豐"];
? ? for (int i = 0; i < 8 ; i ++) {
? ? ? ? UILabel *labelTT = [[UILabel alloc]initWithFrame:CGRectMake((X+width)*i, 150, width, 20)];
? ? ? ? labelTT.text = array[i];
? ? ? ? labelTT.textColor = [UIColor whiteColor];
? ? ? ? labelTT.font = [UIFont systemFontOfSize:12];
? ? ? ? [views addSubview:labelTT];
? ? }
}
@end
TwoTableViewCell.m
#import "TwoTableViewCell.h"
#import "MyButton.h"
#import "TwoBtn.h"
@implementation TwoTableViewCell
{
? ? TwoBtn *btn1;
? ? TwoBtn *btn2;
? ? TwoBtn *btn3;
? ? TwoBtn *btn4;
? ? TwoBtn *btn5;
? ? TwoBtn *btn6;
? ? TwoBtn *btn7;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
? ? if (self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
? ? ? ? [self setUI];
? ? }
? ? return self;
}
- (void)setUI
{
? ? btn1 = [[TwoBtn alloc]initWithFrame:CGRectMake(15, 10, 60, 60)];
? ? btn1.titleEdgeInsets = UIEdgeInsetsMake(80, 0, 0, 0);
? ? btn1.titleLabel.textAlignment = NSTextAlignmentCenter;
? ? [btn1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
? ? btn1.titleLabel.font = [UIFont systemFontOfSize:13];
? ? [btn1 setTitle:@"漢堡薯?xiàng)l" forState:UIControlStateNormal];
? ? [btn1 setImage:[UIImage imageNamed:@"Food2"] forState:UIControlStateNormal];
? ? btn2 = [[TwoBtn alloc]initWithFrame:CGRectMake(115, 10, 60, 60)];
? ? btn2.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 50, 10);
? ? btn2.titleEdgeInsets = UIEdgeInsetsMake(80, 0, 0, 0);
? ? btn2.titleLabel.textAlignment = NSTextAlignmentCenter;
? ? [btn2 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
? ? btn2.titleLabel.font = [UIFont systemFontOfSize:13];
? ? btn2.titleLabel.textAlignment = NSTextAlignmentCenter;
? ? [btn2 setTitle:@"包子粥店" forState:UIControlStateNormal];
? ? [btn2 setImage:[UIImage imageNamed:@"Food3"] forState:UIControlStateNormal];
? ? btn3 = [[TwoBtn alloc]initWithFrame:CGRectMake(215, 10, 60, 60)];
? ? btn3.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 50, 10);
? ? btn3.titleEdgeInsets = UIEdgeInsetsMake(80, 0, 0, 0);
? ? [btn3 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
? ? btn3.titleLabel.font = [UIFont systemFontOfSize:13];
? ? btn3.titleLabel.textAlignment = NSTextAlignmentCenter;
? ? [btn3 setTitle:@"鮮花蛋糕" forState:UIControlStateNormal];
? ? [btn3 setImage:[UIImage imageNamed:@"Food4"] forState:UIControlStateNormal];
? ? btn4 = [[TwoBtn alloc]initWithFrame:CGRectMake(315, 10, 60, 60)];
? ? btn4.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 50, 10);
? ? btn4.titleEdgeInsets = UIEdgeInsetsMake(80, 0, 0, 0);
? ? [btn4 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
? ? btn4.titleLabel.font = [UIFont systemFontOfSize:13];
? ? btn4.titleLabel.textAlignment = NSTextAlignmentCenter;
? ? [btn4 setTitle:@"麻辣燙" forState:UIControlStateNormal];
? ? [btn4 setImage:[UIImage imageNamed:@"Food5"] forState:UIControlStateNormal];
? ? btn5 = [[TwoBtn alloc]initWithFrame:CGRectMake(15, 100, 60, 60)];
? ? btn5.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 50, 10);
? ? btn5.titleEdgeInsets = UIEdgeInsetsMake(80, 0, 0, 0);
? ? [btn5 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
? ? btn5.titleLabel.font = [UIFont systemFontOfSize:13];
? ? btn5.titleLabel.textAlignment = NSTextAlignmentCenter;
? ? [btn5 setTitle:@"地方菜" forState:UIControlStateNormal];
? ? [btn5 setImage:[UIImage imageNamed:@"Food5"] forState:UIControlStateNormal];
? ? btn6 = [[TwoBtn alloc]initWithFrame:CGRectMake(115, 100, 60, 60)];
? ? btn6.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 50, 10);
? ? btn6.titleEdgeInsets = UIEdgeInsetsMake(80, 0, 0, 0);
? ? [btn6 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
? ? btn6.titleLabel.font = [UIFont systemFontOfSize:13];
? ? btn6.titleLabel.textAlignment = NSTextAlignmentCenter;
? ? [btn6 setTitle:@"披薩意面" forState:UIControlStateNormal];
? ? [btn6 setImage:[UIImage imageNamed:@"Food5"] forState:UIControlStateNormal];
? ? btn7 = [[TwoBtn alloc]initWithFrame:CGRectMake(215, 100, 60, 60)];
? ? btn7.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 50, 10);
? ? btn7.titleEdgeInsets = UIEdgeInsetsMake(80, 0, 0, 0);
? ? [btn7 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
? ? btn7.titleLabel.font = [UIFont systemFontOfSize:13];
? ? btn7.titleLabel.textAlignment = NSTextAlignmentCenter;
? ? [btn7 setTitle:@"異國料理" forState:UIControlStateNormal];
? ? [btn7 setImage:[UIImage imageNamed:@"Food5"] forState:UIControlStateNormal];
? ? [self.contentView addSubview:btn1];
? ? [self.contentView addSubview:btn2];
? ? [self.contentView addSubview:btn3];
? ? [self.contentView addSubview:btn4];
? ? [self.contentView addSubview:btn5];
? ? [self.contentView addSubview:btn6];
? ? [self.contentView addSubview:btn7];
//? ? CGFloat width = 60;
//? ? CGFloat height = 60;
//? ? CGFloat X = 10+width;
//? ? NSArray *array = [NSArray array];
//? ? array = @[@"漢堡薯?xiàng)l",@"包子粥店",@"鮮花蛋糕",@"麻辣燙"];
//? ? NSArray *arrays = [NSArray array];
//? ? arrays = @[@"Food1",@"Food2",@"Food3",@"Food4"];
//? ? for (int i = 0; i < 4; i ++) {
//? ? ? ? MyButton *btns =[[MyButton alloc]initWithFrame:CGRectMake(X*i, 20, width, height)];
//? ? ? ? [btns setImage:[UIImage imageNamed:arrays[i]] forState:UIControlStateNormal];
//? ? ? ? [btns setTitle:array[i] forState:UIControlStateNormal];
//? ? ? ? [btns setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//? ? ? ? btns.titleLabel.font = [UIFont systemFontOfSize:13];
//? ? ? ? btns.titleLabel.textAlignment = NSTextAlignmentCenter;
//? ? ? ? [self.contentView addSubview:btns];
//? ? }
}
@end
ThreeTableViewCell.m
#import "ThreeTableViewCell.h"
@implementation ThreeTableViewCell
{
? ? //實(shí)現(xiàn)三個(gè)屬性
? ? UIScrollView *scroll;
? ? NSArray *imgArr;//圖片
? ? UIPageControl *page;//頁面
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
? ? if (self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
? ? ? ? [self CustomUI];
? ? }
? ? return self;
}
- (void)CustomUI
{
? ? scroll = [[UIScrollView alloc]initWithFrame:CGRectMake(8, 5, 398, 100)];
? ? [self.contentView addSubview:scroll];
? ? imgArr = @[@"切片1",@"899724a811384b1c24b081ba456df08f.jpg.png",@"b7d69dc73c527365a8826b0d753aaea7.jpg"];
? ? //設(shè)置圖片進(jìn)行滾動(dòng)
? ? scroll.pagingEnabled = YES;
? ? for (int i = 0; i < imgArr.count; i++)
? ? {
? ? ? ? UIImageView *img = [[UIImageView alloc]initWithFrame:CGRectMake(398 * i, 0, 398, 100)];
? ? ? ? img.userInteractionEnabled = YES;
? ? ? ? img.image = [UIImage imageNamed:imgArr[i]];
? ? ? ? [scroll addSubview:img];
? ? }
? ? scroll.contentSize = CGSizeMake(398 * imgArr.count, 100);
? ? //取消彈簧效果
? ? scroll.bounces = NO;
? ? //隱藏滾動(dòng)條
? ? scroll.showsHorizontalScrollIndicator = NO;
? ? //頁碼? (點(diǎn))
? ? page = [[UIPageControl alloc]initWithFrame:CGRectMake((398 -100) / 2, 80, 100, 20)];
? ? page.numberOfPages = imgArr.count;
? ? //設(shè)置初始頁碼
? ? page.currentPage = 0;
? ? //設(shè)置頁碼的顏色
? ? page.pageIndicatorTintColor = [UIColor grayColor];
? ? [self.contentView addSubview:page];
//? ? UIImageView *images = [[UIImageView alloc]initWithFrame:CGRectMake(8, 5, 398, 100)];
//? ? images.image = [UIImage imageNamed:@"切片1"];
//? ? [self.contentView addSubview:images];
//
? ? UIView *views = [[UIView alloc]initWithFrame:CGRectMake(0, 110, 414, 8)];
? ? views.backgroundColor = [UIColor colorWithRed:243/255.0 green:243/255.0 blue:243/255.0 alpha:1.0];
? ? [self.contentView addSubview:views];
}
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
? ? NSLog(@"contentOffset: x: %f,y: %f",scrollView.contentOffset.x,scrollView.contentOffset.y);
? ? //求余
? ? NSInteger index = scroll.contentOffset.x / scrollView.frame.size.width;
? ? page.currentPage = index;
}
@end
FourTableViewCell.m
#import "FourTableViewCell.h"
#import "MyButton.h"
@implementation FourTableViewCell
{
? ? MyButton *buttom1;
? ? MyButton *buttom2;
? ? MyButton *buttom3;
? ? MyButton *buttom4;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
? ? if (self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
? ? ? ? [self customUI];
? ? }
? ? return self;
}
- (void)customUI
{
? ? self.backgroundColor = [UIColor colorWithRed:243/255.0 green:243/255.0 blue:243/255.0 alpha:1.0];
? ? buttom1 = [[MyButton alloc]initWithFrame:CGRectMake(0, 0, 206, 75)];
? ? buttom1.backgroundColor = [UIColor whiteColor];
? ? buttom1.titleLabel.textAlignment = NSTextAlignmentCenter;
? ? [buttom1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
? ? buttom1.titleLabel.font = [UIFont systemFontOfSize:15 weight:2];
? ? [buttom1 setTitle:@"四星晚餐" forState:UIControlStateNormal];
? ? [buttom1 setImage:[UIImage imageNamed:@"Food1"] forState:UIControlStateNormal];
? ? [self.contentView addSubview:buttom1];
? ? UILabel *label1 = [[UILabel alloc]initWithFrame:CGRectMake(28, 40, 100, 20)];
? ? label1.text = @"滿40減20起";
? ? label1.textColor = [UIColor lightGrayColor];
? ? label1.font = [UIFont systemFontOfSize:12];
? ? [buttom1 addSubview:label1];
? ? buttom2 = [[MyButton alloc]initWithFrame:CGRectMake(207, 0, 207, 75)];
? ? buttom2.backgroundColor = [UIColor whiteColor];
? ? buttom2.titleLabel.textAlignment = NSTextAlignmentCenter;
? ? [buttom2 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
? ? buttom2.titleLabel.font = [UIFont systemFontOfSize:15 weight:2];
? ? [buttom2 setTitle:@"霸王餐" forState:UIControlStateNormal];
? ? [buttom2 setImage:[UIImage imageNamed:@"Food2"] forState:UIControlStateNormal];
? ? [self.contentView addSubview:buttom2];
? ? UILabel *label2 = [[UILabel alloc]initWithFrame:CGRectMake(35, 40, 100, 20)];
? ? label2.text = @"領(lǐng)20元紅包";
? ? label2.textColor = [UIColor lightGrayColor];
? ? label2.font = [UIFont systemFontOfSize:12];
? ? [buttom2 addSubview:label2];
? ? buttom3 = [[MyButton alloc]initWithFrame:CGRectMake(0, 76, 206, 75)];
? ? buttom3.backgroundColor = [UIColor whiteColor];
? ? buttom3.titleLabel.textAlignment = NSTextAlignmentCenter;
? ? [buttom3 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
? ? buttom3.titleLabel.font = [UIFont systemFontOfSize:15 weight:2];
? ? [buttom3 setTitle:@"快選加班餐" forState:UIControlStateNormal];
? ? [buttom3 setImage:[UIImage imageNamed:@"Food3"] forState:UIControlStateNormal];
? ? [self.contentView addSubview:buttom3];
? ? UILabel *label3 = [[UILabel alloc]initWithFrame:CGRectMake(28, 40, 100, 20)];
? ? label3.text = @"低至5折";
? ? label3.textColor = [UIColor lightGrayColor];
? ? label3.font = [UIFont systemFontOfSize:12];
? ? [buttom3 addSubview:label3];
? ? buttom4 = [[MyButton alloc]initWithFrame:CGRectMake(207, 76, 207, 75)];
? ? buttom4.backgroundColor = [UIColor whiteColor];
? ? buttom4.titleLabel.textAlignment = NSTextAlignmentCenter;
? ? [buttom4 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
? ? buttom4.titleLabel.font = [UIFont systemFontOfSize:15 weight:2];
? ? [buttom4 setTitle:@"立減10元" forState:UIControlStateNormal];
? ? [buttom4 setImage:[UIImage imageNamed:@"Food4"] forState:UIControlStateNormal];
? ? [self.contentView addSubview:buttom4];
? ? UILabel *label4 = [[UILabel alloc]initWithFrame:CGRectMake(35, 40, 100, 20)];
? ? label4.text = @"周二開胃菜";
? ? label4.textColor = [UIColor lightGrayColor];
? ? label4.font = [UIFont systemFontOfSize:12];
? ? [buttom4 addSubview:label4];
}
@end
ViewController.m
#import "ViewController.h"#import "OneTableViewCell.h"#import "TwoTableViewCell.h"#import "ThreeTableViewCell.h"#import "FourTableViewCell.h"static NSString *cellid = @"deliciousCell";static NSString *cellids = @"functionCell";static NSString *cellidss = @"menucell";static NSString *contentid = @"contentcell";@interface ViewController ()@property (nonatomic,strong)UITableView *tables;
@end
@implementation ViewController
- (void)viewDidLoad {
? ? [super viewDidLoad];
? ? self.view.backgroundColor = [UIColor whiteColor];
? ? self.navigationController.navigationBarHidden = YES;
? ? [self tables];
}
- (UITableView *)tables
{
? ? if (!_tables) {
? ? ? ? _tables = [[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStylePlain];
? ? ? ? _tables.delegate = self;
? ? ? ? _tables.dataSource = self;
? ? ? ? [_tables registerClass:[OneTableViewCell class] forCellReuseIdentifier:cellid];
? ? ? ? [_tables registerClass:[TwoTableViewCell class] forCellReuseIdentifier:cellids];
? ? ? ? [_tables registerClass:[ThreeTableViewCell class] forCellReuseIdentifier:cellidss];
? ? ? ? [_tables registerClass:[FourTableViewCell class] forCellReuseIdentifier:contentid];
? ? ? ? [self.view addSubview:_tables];
? ? }
? ? return _tables;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
? ? return 4;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
? ? return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
? ? UITableViewCell *cell;
? ? switch (indexPath.section)
? ? {
? ? ? ? case 0:{
? ? ? ? ? ? OneTableViewCell *Ocells = [tableView dequeueReusableCellWithIdentifier:cellid];
? ? ? ? ? ? if (!Ocells) {
? ? ? ? ? ? ? ? Ocells = [[OneTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid];
? ? ? ? ? ? }
? ? ? ? ? ? return Ocells;
? ? ? ? }
? ? ? ? ? ? break;
? ? ? ? case 1:{
? ? ? ? ? ? TwoTableViewCell *Tcells = [tableView dequeueReusableCellWithIdentifier:cellids];
? ? ? ? ? ? if (!Tcells) {
? ? ? ? ? ? ? ? Tcells = [[TwoTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellids];
? ? ? ? ? ? }
? ? ? ? ? ? return Tcells;
? ? ? ? }
? ? ? ? ? ? break;
? ? ? ? case 2:{
? ? ? ? ? ? ThreeTableViewCell *Ttcells = [tableView dequeueReusableCellWithIdentifier:cellidss];
? ? ? ? ? ? if (!Ttcells) {
? ? ? ? ? ? ? ? Ttcells = [[ThreeTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellidss];
? ? ? ? ? ? }
? ? ? ? ? ? return Ttcells;
? ? ? ? }
? ? ? ? ? ? break;
? ? ? ? case 3:
? ? ? ? {
? ? ? ? ? ? FourTableViewCell *fcells = [tableView dequeueReusableCellWithIdentifier:contentid];
? ? ? ? ? ? if (!fcells) {
? ? ? ? ? ? ? ? fcells = [[FourTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:contentid];
? ? ? ? ? ? }
? ? ? ? ? ? return fcells;
? ? ? ? }
? ? ? ? ? ? break;
? ? ? ? default:
? ? ? ? {
? ? ? ? ? ? cell = [tableView dequeueReusableCellWithIdentifier:@""];
? ? ? ? ? ? if (!cell)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@""];
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? ? ? break;
? ? }
? ? return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
? ? if (indexPath.section == 0) {
? ? ? ? return 180;
? ? }
? ? else if (indexPath.section ==1){
? ? ? ? return 180;
? ? }
? ? else if (indexPath.section == 2){
? ? ? ? return 119;
? ? }
? ? else if (indexPath.section == 3){
? ? ? ? return 158;
? ? }
? ? return 0;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
? ? [_tables deselectRowAtIndexPath:indexPath animated:YES];
}
@end
SecondViewController.m
ThirdViewController.m
FourViewController.m
self.view.backgroundColor = [UIColor whiteColor];