【iOS】APP仿写——3G share仿写

前言

本周进行了3G share的仿写,这个仿写内容较多,用到了很多之前学习的东西,也学习了许多的新知识。

登录、注册界面

这两个界面主要运用属性传值和协议传值,将注册的账号密码通过协议传值传递给登陆界面,登陆界面再通过属性传值将保存账号密码的字典传递给注册界面,避免重复注册,这里我们需要注意的是,注册界面保存数据的字典如果初始化的话,就无法接收到来自登陆界面已经注册过的数据,解决办法就是在登陆界面初始化。

    VCregister* vcregister = [[VCregister alloc] init];
    vcregister.dictshou = [NSMutableDictionary dictionary];
    [vcregister.dictshou addEntriesFromDictionary:self.dict];
    vcregister.delegate = self;
    [self presentViewController:vcregister animated:YES completion:nil];

在密码账号确认后进入主页,通过协议传值,将我给主界面创建的内容告诉SCeneDelegate,在里面设定新的根视图控制器,进入主页。

        VCshouye* vcshouye = [[VCshouye alloc] init];
        VCsearch* vcsearch = [[VCsearch alloc] init];
        VCwenzhang* vcwenzhang = [[VCwenzhang alloc] init];
        VCactivity* vcactivity = [[VCactivity alloc] init];
        VCwode* vcwode = [[VCwode alloc] init];
        
        UITabBarController* tb = [[UITabBarController alloc] init];
        
        UINavigationController* navvcshouye = [[UINavigationController alloc] initWithRootViewController:vcshouye];
        UINavigationController* navvcsearch = [[UINavigationController alloc] initWithRootViewController:vcsearch];
        UINavigationController* navvcwenzhang = [[UINavigationController alloc] initWithRootViewController:vcwenzhang];
        UINavigationController* navvcactivity = [[UINavigationController alloc] initWithRootViewController:vcactivity];
        UINavigationController* navvcwode = [[UINavigationController alloc] initWithRootViewController:vcwode];

        UITabBarItem* tbshouye = [[UITabBarItem alloc] initWithTitle:nil image:[[UIImage imageNamed:@"button1_normal.png"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] selectedImage:[[UIImage imageNamed:@"button1_pressed.png"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
        navvcshouye.tabBarItem = tbshouye;
        UITabBarItem* tbsearch = [[UITabBarItem alloc] initWithTitle:nil image:[[UIImage imageNamed:@"button2_normal.png"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] selectedImage:[[UIImage imageNamed:@"button2_pressed.png"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
        navvcsearch.tabBarItem = tbsearch;
        UITabBarItem* tbwenzhang = [[UITabBarItem alloc] initWithTitle:nil image:[[UIImage imageNamed:@"button3_normal.png"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] selectedImage:[[UIImage imageNamed:@"button3_pressed.png"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
        navvcwenzhang.tabBarItem = tbwenzhang;
        UITabBarItem* tbactivity = [[UITabBarItem alloc] initWithTitle:nil image:[[UIImage imageNamed:@"button4_normal.png"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] selectedImage:[[UIImage imageNamed:@"button4_pressed.png"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
        navvcactivity.tabBarItem = tbactivity;
        UITabBarItem* tbwode = [[UITabBarItem alloc] initWithTitle:nil image:[[UIImage imageNamed:@"button5_normal.png"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] selectedImage:[[UIImage imageNamed:@"button5_pressed.png"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
        navvcwode.tabBarItem = tbwode;
        NSArray* arr = [NSArray arrayWithObjects:navvcshouye, navvcsearch, navvcwenzhang, navvcactivity, navvcwode, nil];
        tb.viewControllers = arr;
        [self.delegate AddTabBar:tb];

在输入还要注意对于非法输入的判断,要限制输入的字符长度和不能允许输入特殊字符等。

效果图
在这里插入图片描述

首页

这个界面主要是一个无限轮播图和一个tableview组成,无限轮播图在之前ZARA和网易云音乐的仿写中已经讲过,这里就不多进行赘述了,主要是将tableview中点赞的值传递给点击打开的界面,这里我使用属性传值和协议传值完成。

        NSLog(@"属性");
        VC1* vc1 = [[VC1 alloc] init];
        vc1.arr = [self.arr1 mutableCopy];
        vc1.delegate = self;
        [self.navigationController pushViewController:vc1 animated:YES];

- (void)GoAString:(NSMutableArray *)arr1
{
    self.arr = [arr1 mutableCopy];
    NSLog(@"%@", self.arr);
    NSLog(@"%@",arr1) ;
    
    [self.tableview beginUpdates];
    NSIndexPath* indexoath1 = [NSIndexPath indexPathForRow:0 inSection:1];
    NSArray* indexpaths = @[indexoath1];
    [self.tableview reloadRowsAtIndexPaths:indexpaths withRowAnimation:UITableViewRowAnimationNone];
    [self.tableview endUpdates];
}

效果图
在这里插入图片描述

搜索

这个界面要实现的内容比较多,更换上传的图片,折叠cell还有搜索。

搜索

这里我使用的是UITextField控件,通过对输入的text是否为大白进行判断,从而push进子视图中,展示子视图的内容,子视图中是一个TableView这里就不多做解释了。

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    NSString* str = @"大白";
    if([self.textfield.text isEqual:str]) {
        VCsou* vc2 = [[VCsou alloc] init];
        [self.navigationController pushViewController:vc2 animated:YES];
    }
    self.textfield.text = @"";
    [textField resignFirstResponder];
    return YES;
}

更换照片

这里更换上传的照片其实和网易云中使用的更换头像逻辑一样,这里需要每次显示上传图片的第一张,我选择将照片的名字存入一个可变数组,每次操作完成后数组中第一个元素就是选择的第一张照片,同时记得将选择照片的数量传递回来。

-(void)press:(UIButton*)button
{
    button.selected = !button.selected;
    if(button.selected) {
        self.selectedCount++;
        [self.arr addObject:@(button.tag-99)];
    } else {
        self.selectedCount--;
        [self.arr removeObject:@(button.tag-99)];
    }
    NSLog(@"%@",self.arr);
}

-(void) find
{
    
    if(self.selectedCount>0)
    {
        NSString* str = [NSString stringWithFormat:@"头像%@.JPG",self.arr[0]];
        UIImage* image = [UIImage imageNamed:str];
        NSLog(@"%@", str);
        
        self.elertView = [UIAlertController alertControllerWithTitle:@"提示" message:@"确定所选内容" preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction* action = [UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:^(UIAlertAction* action){
            
            [self.delegate ChangePhoto:image andCount:self.selectedCount];
            [self.navigationController popViewControllerAnimated:YES];
        }];
        [self.elertView addAction: action];
        [self presentViewController:self.elertView animated:YES completion:nil];
    } else {
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"您并未更改图片" preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction *cofirm = [UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:^(UIAlertAction* action){
            [self.navigationController popViewControllerAnimated:YES];
        }];
        [alert addAction:cofirm];
        [self presentViewController:alert animated:YES completion:nil];
    }
}

折叠cell

折叠cell其实就是在打开时展示整个tableview,折叠时仅展示第一个cell的一个UITableview,实现起来并不是很难,下面我通过代码讲解我是如何实现折叠cell的。
代码

self.tableview  = [[UITableView alloc] initWithFrame:CGRectMake(270, 200, 95, 20) style:UITableViewStylePlain];
    self.tableview.delegate = self;
    self.tableview.dataSource = self;
    _cellarr = [NSMutableArray arrayWithObjects:@"原创作品", @"设计资料", @"设计师观点", @"设计教程", nil];
    _zhedie = [UIButton buttonWithType:UIButtonTypeSystem];
    _zhedie.frame = CGRectMake(365, 200, 20, 20);
    _zhedie.backgroundColor = [UIColor whiteColor];
    [_zhedie setImage:[UIImage imageNamed:@"未勾选.png"] forState:UIControlStateNormal];
    [_zhedie addTarget:self action:@selector(pressUp:)
          forControlEvents:UIControlEventTouchUpInside];
    _zhedie.tag = 1001;
    [self.view addSubview:_zhedie];
    [self.view addSubview:self.tableview];
    if (_zhedie.tag == 1001) {
        _tableview.frame = CGRectMake(270, 200, 95, 20);
    }

上面这段代码是在viewDidload中设置tableview的参数,可以看到,初始设置的范围中仅仅高度时展示一个cell的高度。

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 4;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 20;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    NSString *selectedItem = _cellarr[indexPath.section];
    [_cellarr removeObjectAtIndex:indexPath.section];//在选择放在第一个的cell时,先删除这个字符串从数组中
    [_cellarr insertObject:selectedItem atIndex:0];//在将这个字符串添加在数组的第一位,刷新tableview后就会展示这个字符串。
    
    [self.tableview reloadData];
    [self pressUp:_zhedie];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    NSString *strID = @"ID";
    //尝试获取可以复用的单元格
    //如果得不到,返回为nil
    UITableViewCell *cell = [_tableview dequeueReusableCellWithIdentifier:strID];
    
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:strID];
    }
    //单元格文字赋值
    cell.textLabel.text = [_cellarr objectAtIndex:indexPath.section];
    cell.textLabel.font = [UIFont systemFontOfSize:12.0];
    cell.textLabel.textAlignment = NSTextAlignmentLeft;

    return cell;
}


-(void)pressUp:(UIButton *)btn {
   if (btn.tag == 1002) {
       [btn setImage:[UIImage imageNamed:@"未勾选.png"] forState:UIControlStateNormal];
       _tableview.frame = CGRectMake(270, 200, 95, 20);
       btn.tag--;
   } else {
       [btn setImage:[UIImage imageNamed:@"已勾选.png"] forState:UIControlStateNormal];
       _tableview.frame = CGRectMake(270, 200, 95, 80);
       btn.tag++;
   }
}//这个代码是按钮点击时调用的,可以看到打开时tableview的高度变成四倍,完成的展示整个UITableView

效果图
在这里插入图片描述

文章

这里使用的是一个滚动视图中放入三个UITableView,在整页显示,同时与分栏控件相匹配即可。
在这里插入图片描述

活动

这里就是一个简单的TableView,比较简单,不多做解释。
在这里插入图片描述

我的

这个界面内容较多,比较冗杂,其中关注要保证退出后不会消失选中状态,我使用将视图控制器当作属性赋给钱一个视图,这样就不会刷新视图了
在这里插入图片描述

                if(!self.shezhi)
                self.shezhi = [[VCshezhi alloc] init];
                [self.navigationController pushViewController:self.shezhi animated:YES];
                break;

效果图
在这里插入图片描述

这就是这个仿写全部的内容了,这个仿写中运用了很多之前学习的内容,也新学习了许多的知识,总的来说收获满满。

  • 31
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
SQLAlchemy 是一个 SQL 工具包和对象关系映射(ORM)库,用于 Python 编程语言。它提供了一个高级的 SQL 工具和对象关系映射工具,允许开发者以 Python 类和对象的形式操作数据库,而无需编写大量的 SQL 语句。SQLAlchemy 建立在 DBAPI 之上,支持多种数据库后端,如 SQLite, MySQL, PostgreSQL 等。 SQLAlchemy 的核心功能: 对象关系映射(ORM): SQLAlchemy 允许开发者使用 Python 类来表示数据库表,使用类的实例表示表中的行。 开发者可以定义类之间的关系(如一对多、多对多),SQLAlchemy 会自动处理这些关系在数据库中的映射。 通过 ORM,开发者可以像操作 Python 对象一样操作数据库,这大大简化了数据库操作的复杂性。 表达式语言: SQLAlchemy 提供了一个丰富的 SQL 表达式语言,允许开发者以 Python 表达式的方式编写复杂的 SQL 查询。 表达式语言提供了对 SQL 语句的灵活控制,同时保持了代码的可读性和可维护性。 数据库引擎和连接池: SQLAlchemy 支持多种数据库后端,并且为每种后端提供了对应的数据库引擎。 它还提供了连接池管理功能,以优化数据库连接的创建、使用和释放。 会话管理: SQLAlchemy 使用会话(Session)来管理对象的持久化状态。 会话提供了一个工作单元(unit of work)和身份映射(identity map)的概念,使得对象的状态管理和查询更加高效。 事件系统: SQLAlchemy 提供了一个事件系统,允许开发者在 ORM 的各个生命周期阶段插入自定义的钩子函数。 这使得开发者可以在对象加载、修改、删除等操作时执行额外的逻辑。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值