IOS之校园APP(部分实现)

个人贡献

实现设置中心页面的内容
在这里插入图片描述

代码与截图

设置中心

在这里插入图片描述
主页面tableview中cell的设置

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"reuse" forIndexPath:indexPath];
    if (indexPath.section == 0) {
        UIImage * icon = [UIImage imageNamed:@"timg"];
        CGSize itemSize = CGSizeMake(50, 50);//固定图片大小为50*50
        UIGraphicsBeginImageContextWithOptions(itemSize, NO, 0.0);//*1
        CGRect imageRect = CGRectMake(0, 0, itemSize.width, itemSize.height);
        [icon drawInRect:imageRect];
        cell.imageView.image = UIGraphicsGetImageFromCurrentImageContext();//*2
        UIGraphicsEndImageContext();//*3
        cell.textLabel.text = _Data[@"Name"];
    }
    if (indexPath.section == 1) {
        UIImage * icon = [UIImage imageNamed:@"notice"];
        CGSize itemSize = CGSizeMake(32, 32);//固定图片大小为36*36
        UIGraphicsBeginImageContextWithOptions(itemSize, NO, 0.0);//*1
        CGRect imageRect = CGRectMake(0, 0, itemSize.width, itemSize.height);
        [icon drawInRect:imageRect];
        cell.imageView.image = UIGraphicsGetImageFromCurrentImageContext();//*2
        UIGraphicsEndImageContext();//*3
        cell.textLabel.text = @"通知";
        int n = [single sharedInstance].r_count+[single sharedInstance].l_count;
        
        if (n >= 99) {
            [cell pp_addBadgeWithNumber:99];
            
        }
        else {
            [cell pp_addBadgeWithNumber:n];
        }
        
        [cell pp_setBadgeHeight:25];
        [cell pp_moveBadgeWithX:-30 Y:25];
    }
    if (indexPath.section == 2) {
        UIImage * icon = [UIImage imageNamed:@"memory"];
        CGSize itemSize = CGSizeMake(32, 32);//固定图片大小为36*36
        UIGraphicsBeginImageContextWithOptions(itemSize, NO, 0.0);//*1
        CGRect imageRect = CGRectMake(0, 0, itemSize.width, itemSize.height);
        [icon drawInRect:imageRect];
        cell.imageView.image = UIGraphicsGetImageFromCurrentImageContext();//*2
        UIGraphicsEndImageContext();//*3
        cell.textLabel.text = @"存储";
    }
    if (indexPath.section == 3) {
        UIImage * icon = [UIImage imageNamed:@"setting"];
        CGSize itemSize = CGSizeMake(32, 32);//固定图片大小为36*36
        UIGraphicsBeginImageContextWithOptions(itemSize, NO, 0.0);//*1
        CGRect imageRect = CGRectMake(0, 0, itemSize.width, itemSize.height);
        [icon drawInRect:imageRect];
        cell.imageView.image = UIGraphicsGetImageFromCurrentImageContext();//*2
        UIGraphicsEndImageContext();//*3
        cell.textLabel.text = @"设置";
    }
    if (indexPath.section == 4) {
        _exit = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        [cell.contentView addSubview:_exit];
        [_exit mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(cell.contentView);
            make.centerX.equalTo(cell.contentView);
            make.width.equalTo(cell.contentView.mas_width).multipliedBy(1);
            make.height.equalTo(cell.contentView.mas_height).multipliedBy(1);
        }];
        _exit.backgroundColor = [UIColor redColor];
        [_exit setTitle:@"注销" forState:UIControlStateNormal];
        [_exit addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
        [_exit setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
       
        cell.backgroundColor = [UIColor clearColor];
    }
    return cell;
}

主页面tableview的点击跳转

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    //跳转逻辑判断
    if(indexPath.section == 0) {
        MyViewController *my = [[MyViewController alloc]init];
        [self.navigationController pushViewController:my animated:YES];
        my.title = @"个人中心";
    }
    if(indexPath.section == 1) {
        NoticeViewController *notice = [[NoticeViewController alloc]init];
        [self.navigationController pushViewController:notice animated:YES];
        notice.title = @"通知";
        [self viewWillAppear:1];
    }
    if(indexPath.section == 2) {
        StorageViewController *storage = [[StorageViewController alloc]init];
        [self.navigationController pushViewController:storage animated:YES];
        storage.title = @"存储";
    }
    if(indexPath.section == 3) {
        PersonalViewController *personal = [[PersonalViewController alloc]init];
        [self.navigationController pushViewController:personal animated:YES];
        personal.title = @"设置";
    }
    if(indexPath.section == 4) {
       
    }
}

个人中心

点击带有头像和姓名的cell进入个人中心页面

在这里插入图片描述
个人中心tableview中cell的设置

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle  reuseIdentifier:@"reuse"];
    if (indexPath.row == 0) {
        cell.textLabel.text = @"邮箱";
        cell.detailTextLabel.text = self.Data[@"Email"];
        
    }
    if (indexPath.row == 1) {
        cell.textLabel.text = @"性别";
        NSString *Gender = [NSString stringWithFormat:@"%@",self.Data[@"Info"][@"Gender"]];
        if ([Gender isEqualToString:@"0"])
            cell.detailTextLabel.text = @"男";
        else
            cell.detailTextLabel.text = @"女";
    }
    
    if (indexPath.row == 2) {
        
        cell.textLabel.text = @"班级";
        NSString *Class = [NSString stringWithFormat:@"%@",self.Data[@"Class"]];
        cell.detailTextLabel.text = Class;
    }
    if (indexPath.row == 3) {
        NSString *Bio = [NSString stringWithFormat:@"%@",self.Data[@"Info"][@"Bio"]];
        cell.textLabel.text = @"个人经历";
        cell.detailTextLabel.text = Bio;
    }
    cell.textLabel.font = [UIFont systemFontOfSize:16];
    cell.textLabel.textColor = [UIColor grayColor];
    cell.detailTextLabel.font = [UIFont systemFontOfSize:16];
    cell.indentationLevel = 1.5;
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    return cell;
}

个人中心tableview的点击跳转

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    //跳转逻辑判断
    EditViewController *edit = [[EditViewController alloc] init];
    if(indexPath.row == 3) {
        
        edit.string = self.Data[@"Info"][@"Bio"];
        edit.title = @"修改个人经历";
        edit.label = @"Info";
        [self.navigationController pushViewController:edit animated:YES];

    }
    if(indexPath.section == 1) {
        
    }
    if(indexPath.section == 2) {
        
    }
    if(indexPath.section == 3) {
       
    }
}
-(void) labelTouchUpInside:(UITapGestureRecognizer *)recognizer{

    EditViewController *edit = [[EditViewController alloc] init];
    edit.string = [single sharedInstance].datalist1[0][@"Name"];
    edit.title = @"修改名称";
    edit.label = @"Name";
    
    [[self viewController].navigationController pushViewController: edit animated:YES];
    
}

点击之后的编辑页面
在这里插入图片描述
点击完成之后的跳转以及数据存储

- (void)onClickedOKbtn {
    NSString *tem = _edit.text;
    NSMutableDictionary * a=[NSMutableDictionary dictionaryWithDictionary:[single sharedInstance].datalist1[0]];
    NSString *url2;
    NSDictionary *parameters;
    if ([_label isEqualToString:@"Info"]) {
        NSDictionary *Info = a[@"info"];
        url2 = @"http://172.18.178.56/api/user/info";
        [Info setValue:tem forKey:@"Bio"];
        parameters = @{@"Avatar":a[@"Info"][@"Avatar"],@"Bio":tem,@"Gender":a[@"Info"][@"Gender"],@"Name":a[@"Info"][@"Name"]};
    }
    if ([_label isEqualToString:@"Name"]) {
        url2 = @"http://172.18.178.56/api/user/name";
        parameters = @{@"name":tem};
        [a setValue:tem forKey:_label];
    }
    [single sharedInstance].datalist1[0] = a;
    AFHTTPSessionManager *manage2 = [AFHTTPSessionManager manager];
    // 设置请求体为JSON
    manage2.requestSerializer = [AFJSONRequestSerializer serializer];
    // 设置响应体为JSON
    manage2.responseSerializer = [AFJSONResponseSerializer serializer];
    [manage2 POST:url2 parameters:parameters headers:nil progress:^(NSProgress * _Nonnull uploadProgress){} success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSLog(@"success");
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
    }];
    [self.navigationController popViewControllerAnimated:YES];
}

通知

在这里插入图片描述
通知页面tableview的cell设置`

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle  reuseIdentifier:@"reuse"];
    NSString *t = [NSString stringWithFormat:@"%@",self.Data[indexPath.section][@"Data"][@"Type"]];
    if ([t isEqualToString:@"reply"]) {
        NSString *string = [NSString stringWithFormat:@"%@ %@",self.Data[indexPath.section][@"User"][@"Name"],@"对你进行了评论"];
        cell.textLabel.text = string;
        NSString *str2 = [NSString stringWithFormat:@"%@", self.Data[indexPath.section][@"Data"][@"Content"]];
        
            cell.detailTextLabel.text = str2;
        NSString *str3 = [NSString stringWithFormat:@"%@", self.Data[indexPath.section][@"Data"][@"Read"]];
        if ([str3 isEqualToString:@"0"]) {
            [cell pp_addDotWithColor:[UIColor redColor]];
            [cell pp_setBadgeHeight:8];
            [cell pp_moveBadgeWithX:-20 Y:15];
        }
        else {
            [cell pp_addDotWithColor:nil];
        }
    }
    else {
        NSString *string = [NSString stringWithFormat:@"%@ %@",self.Data[indexPath.section][@"User"][@"Name"],@"赞了你"];
        cell.detailTextLabel.text = string;
        NSString *str3 = [NSString stringWithFormat:@"%@", self.Data[indexPath.section][@"Data"][@"Read"]];
        if ([str3 isEqualToString:@"0"]) {
            [cell pp_addDotWithColor:[UIColor redColor]];
            [cell pp_setBadgeHeight:8];
            [cell pp_moveBadgeWithX:-20 Y:15];
        }
        else {
            [cell pp_addDotWithColor:nil];
        }
    }
    cell.textLabel.font = [UIFont systemFontOfSize:16];
    cell.textLabel.textColor = [UIColor grayColor];
    cell.detailTextLabel.font = [UIFont systemFontOfSize:16];
    cell.indentationLevel = 1;
    [cell.layer setMasksToBounds:YES];
    
    cell.layer.cornerRadius=5;
    cell.layer.borderWidth = 1;
//    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    return cell;
}

点击取消红点

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    NSString *url3;
    
        url3 = [NSString stringWithFormat:@"%@%@", @"http://172.18.178.56/api/notification/read/",self.Data[indexPath.section][@"Data"][@"ID"]];
    
    
    NSDictionary *parameters = @{@"Read": @"true"};
    AFHTTPSessionManager *manage3 = [AFHTTPSessionManager manager];
    // 设置请求体为JSON
    manage3.requestSerializer = [AFJSONRequestSerializer serializer];
    // 设置响应体为JSON
    manage3.responseSerializer = [AFJSONResponseSerializer serializer];
    [manage3 PATCH:url3 parameters:parameters headers:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        [self.tableView reloadData];
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
    }];
    
}

在这里插入图片描述

左划删除按钮

-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    //处理删除的操作
    NSString *url3;
    
        url3 = [NSString stringWithFormat:@"%@%@", @"http://172.18.178.56/api/notification/",self.Data[indexPath.section][@"Data"][@"ID"]];
    
    
    AFHTTPSessionManager *manage3 = [AFHTTPSessionManager manager];
    // 设置请求体为JSON
    manage3.requestSerializer = [AFJSONRequestSerializer serializer];
    // 设置响应体为JSON
    manage3.responseSerializer = [AFJSONResponseSerializer serializer];
    [manage3 DELETE:url3 parameters:nil headers:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        NSString *url4 = @"http://172.18.178.56/api/notification/all";
        
        AFHTTPSessionManager *manage3 = [AFHTTPSessionManager manager];
        // 设置请求体为JSON
        manage3.requestSerializer = [AFJSONRequestSerializer serializer];
        // 设置响应体为JSON
        manage3.responseSerializer = [AFJSONResponseSerializer serializer];
        [manage3 GET:url4 parameters:nil headers:nil progress:^(NSProgress * _Nonnull uploadProgress){} success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            NSDictionary *returndata = (NSDictionary*)responseObject;
            self.Data = [[NSMutableArray alloc] init];
            self.Data = (NSMutableArray*)returndata[@"Notification"];
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        }];
        
        [self.tableView reloadData];
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
    }];
}

存储

在这里插入图片描述
存储页面布局

UILabel *detail = [[UILabel alloc] init];
    [self.view addSubview:detail];
    [detail mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view.mas_top).with.offset(self.view.frame.size.height*0.2);
        make.centerX.equalTo(self.view);
        make.width.equalTo(self.view.mas_width).multipliedBy(0.8);
        make.height.equalTo(self.view.mas_height).multipliedBy(0.3);
    }];
    
    
    detail.backgroundColor = [UIColor whiteColor];
    detail.layer.borderWidth = 1;
    detail.layer.cornerRadius = 10;
    _l1 = [[UILabel alloc] init];
    _l2 = [[UILabel alloc] init];
    _l3 = [[UILabel alloc] init];
    [self.view addSubview:_l1];
    [self.view addSubview:_l2];
    [self.view addSubview:_l3];
    [_l1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view.mas_top).with.offset(self.view.frame.size.height*0.2-50);
        make.left.equalTo(detail.mas_left).with.offset(10);
        make.width.equalTo(self.view.mas_width).multipliedBy(0.8);
        make.height.equalTo(self.view.mas_height).multipliedBy(0.3);
    }];
    [_l2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view.mas_top).with.offset(self.view.frame.size.height*0.2);
        make.left.equalTo(detail.mas_left).with.offset(10);
        make.width.equalTo(self.view.mas_width).multipliedBy(0.8);
        make.height.equalTo(self.view.mas_height).multipliedBy(0.3);
    }];
    [_l3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(detail.mas_top).with.offset(80);
        make.left.equalTo(detail.mas_left).with.offset(10);
        make.width.equalTo(self.view.mas_width).multipliedBy(0.8);
        make.height.equalTo(self.view.mas_height).multipliedBy(0.3);
    }];
    
    NSString *str = [NSString stringWithFormat:@"最大容量:  %@",self.Data[@"MaxSize"]];
    _l1.text = str;
    str = [NSString stringWithFormat:@"已用容量:  %@",self.Data[@"UsedSize"]];
    _l2.text = str;
    str = [NSString stringWithFormat:@"单一容量:  %@",self.Data[@"SingleSize"]];
    _l3.text = str;

注销页面

将登录界面的的navigationcontroller设置为根

问题与解决方法

问题

  1. 从接口获取的JSON数据的运用
  2. tableview的每个section边框设置圆角矩形
  3. 消息通知列表的未读小圆点,以及通知的未读消息统计
  4. 个人信息和通知列表在数据改变后的数据和页面刷新
  5. 不同页面之间的数据传递以及数据更新

解决方法

  1. 从接口获取JSON数据之后将它强制类型转换为NSDictionary类型,然后存储到单例模式中,如果要调用数据则通过key来使用里面的value
	NSDictionary *returndata = (NSDictionary*)responseObject;
	self.Data2 = [[NSMutableArray alloc] init];
	self.Data2 = (NSMutableArray*)returndata[@"Notification"];
	[[single sharedInstance].datalist1 addObject:self.Data2];
  1. tableview的section边框默认是没有,所以为了让每个section都是一个圆角矩形,要利用绘图将每个section的第一个cell的上面两个角设置为圆角,然后将每个section的最后一个cell的下面两个角设置为圆角
	if (indexPath.row == 0) {
        // 初始起点为cell的左下角坐标
        CGPathMoveToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMaxY(bounds));
        // 起始坐标为左下角,设为p,(CGRectGetMinX(bounds), CGRectGetMinY(bounds))为左上角的点,设为p1(x1,y1),(CGRectGetMidX(bounds), CGRectGetMinY(bounds))为顶部中点的点,设为p2(x2,y2)。然后连接p1和p2为一条直线l1,连接初始点p到p1成一条直线l,则在两条直线相交处绘制弧度为r的圆角。
        CGPathAddArcToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMinY(bounds), CGRectGetMidX(bounds), CGRectGetMinY(bounds), cornerRadius);
        CGPathAddArcToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMinY(bounds), CGRectGetMaxX(bounds), CGRectGetMidY(bounds), cornerRadius);
        // 终点坐标为右下角坐标点,把绘图信息都放到路径中去,根据这些路径就构成了一块区域了
        CGPathAddLineToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMaxY(bounds));
        CGPathCloseSubpath(pathRef);

    } else if (indexPath.row == [tableView numberOfRowsInSection:indexPath.section]-1) {
        // 初始起点为cell的左上角坐标
        CGPathMoveToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMinY(bounds));
        CGPathAddArcToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMaxY(bounds), CGRectGetMidX(bounds), CGRectGetMaxY(bounds), cornerRadius);
        CGPathAddArcToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMaxY(bounds), CGRectGetMaxX(bounds), CGRectGetMidY(bounds), cornerRadius);
        // 添加一条直线,终点坐标为右下角坐标点并放到路径中去
        CGPathAddLineToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMinY(bounds));
    } else {
        // 添加cell的rectangle信息到path中(不包括圆角)
        CGPathAddRect(pathRef, nil, bounds);
    }
  1. 未读消息红点和通知列表的未读消息统计利用iOS自定义Badge的来实现,在获取消息列表的数据后计算未读消息的数量,然后在通知页面显示对应的未读消息,在消息列表在生成cell时判断,如果read为false的话就加上未读消息的红点,在cell的点击事件中利用接口将read值改为true并取消红点(因为后端接口问题,read值不能修改为true,所以点击后红点不会消失)
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    NSString *url3;
    url3 = [NSString stringWithFormat:@"%@%@", @"http://172.18.178.56/api/notification/read/",self.Data[indexPath.section][@"Data"][@"ID"]];
    NSDictionary *parameters = @{@"Read": @"true"};
    AFHTTPSessionManager *manage3 = [AFHTTPSessionManager manager];
    // 设置请求体为JSON
    manage3.requestSerializer = [AFJSONRequestSerializer serializer];
    // 设置响应体为JSON
    manage3.responseSerializer = [AFJSONResponseSerializer serializer];
    [manage3 PATCH:url3 parameters:parameters headers:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        [self.tableView reloadData];
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
    }];
    
}
  1. tableview在改变数据之后利用 [self.tableView reloadData] 即可对数据进行刷新,刷新之后tableview就会相应的改变
  2. 页面之间的数据传递使用单例模式将从后端获取的数据保存起来,当其他页面要使用时利用单例模式进行赋值
- (id)init{
    if (self = [super init]){
        self->_datalist1 = [[NSMutableArray alloc ]init];
        self->_imagelist = [[NSMutableArray alloc ]init];
        self->_r_count = 0;
        self->_l_count = 0;
    }
    return self;
}
+(instancetype)sharedInstance{
    static single *myInstance = nil;
    if(myInstance == nil){
        myInstance = [[single alloc]init];
    }
    return myInstance;
}
	self.Data = [single sharedInstance].datalist1[0];

个人总结

这次项目大致功能完成,但由于时间原因对于一些个性化的功能和对UI界面的优化做的不是很好,不过这次期中项目让我学到了很多网络编程和本地存储的知识,对于tableview的运用和界面设计也更加熟悉,还学会了一些数据解析处理的方法,对于JSON类型更加了解。

个人贡献评分 90

思想感悟

这次项目我们小组是分页面进行完成的,在最后代码合成的阶段出了一些问题,让我明白代码拥有好的移植性的优点,以及对于问题考虑的全面性加深了理解,比如对于一些空数据的处理,比如单例模式对于数据的初始化和删除来避免数据的重复或者堆积,这些细节的问题很容易造成程序的崩溃,在之后的作业和项目中应该特别注意

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值