恒美微站 Logo 恒美微站
  • 首页
  • 关于我们
  • 建站服务
  • 主题模板
  • 案例展示
  • 资讯中心
  • 联系我们

【iOS】3G-Share仿写总结

  • 首页
  • 资讯中心
  • /
  • 【iOS】3G-Share仿写总结

相关资讯

电瓶车电子设备防盗指南:从个人习惯到社区协作的全面防护 2026/9/13 12:16:13
异地无犯罪记录公证申办指南|可行性解析及全程办理流程详解 2026/8/2 18:59:14
生命涌现的小龙虾技能之【Virtual Fence Crossing Alert Skill | 虚拟围栏越界预警技能】简介 2026/8/2 18:59:14

最新资讯

Gleam 编译器贡献指南:从提交规范、本地开发到调试与跨平台代码实战
Kilo HTTP 路由模式实践指南:基于 Effect HttpApi 的实例路由架构、错误边界与 OpenAPI 兼容治理
工业运动控制核心三要素:电机、驱动器、控制器的选型与调试实战
PaddlePaddle 安全公告体系全解读:PDSA 公告、漏洞类型分析与防御实践
开关电源电路设计实战:9个实例详解拓扑选型、环路补偿与PCB布局
SpringBoot高校教师工作量管理系统开发实践

今日推荐

AI SDK Harness 依赖更新指南:掌握 harness 包 SDK 依赖的升级、桥接同步与一致性校验
Refine v5 Ant Design NumberField 组件实战:基于 Intl 的本地化数字格式化
Flutter应用改名全指南:从Android到iOS的配置与工具实践

本周热门

AI SDK Harness 依赖更新指南:掌握 harness 包 SDK 依赖的升级、桥接同步与一致性校验
Refine v5 Ant Design NumberField 组件实战:基于 Intl 的本地化数字格式化
Flutter应用改名全指南:从Android到iOS的配置与工具实践

本月精选

自研推理加速器Redwood:两周内实现PyTorch模型高效部署的实战教程
V4L2摄像头采集实战:从camera_client.rar到出图全流程解析
从“谁发明了钢琴键”到知识问答智能体:RAG与记忆工程实践

【iOS】3G-Share仿写总结

发布时间:2026/9/13 12:16:28
【iOS】3G-Share仿写总结 【iOS】3G-Share仿写总结文章目录【iOS】3G-Share仿写总结登录和注册页面首页搜索页面上传页面文章和活动页面个人页面登录和注册页面对于登录页面主要是用NSUserDefaults来存储注册信息然后登录判断是否正确。在邮箱以及账号密码的输入中我们需要用到谓词以及正则表达式来限制具体可见我的博客谓词与正则表达式-(void)registersuccess{NSString*accountself.accountView.textField.text;NSString*passwordself.cipherView.textField.text;if([account isEqualToString:]||[password isEqualToString:]){UIAlertController*alert[UIAlertController alertControllerWithTitle:注册失败message:账号或密码为空preferredStyle:UIAlertControllerStyleAlert];UIAlertAction*confirmAction[UIAlertAction actionWithTitle:确认style:UIAlertActionStyleDefault handler:nil];[alert addAction:confirmAction];[selfpresentViewController:alert animated:YES completion:nil];return;}NSString*emailself.emailView.textField.text;NSString*pattern[A-Z0-9a-z][A-Za-z0-9]\\.[A-Za-z]{2,};NSPredicate*predicate[NSPredicate predicateWithFormat:SELF MATCHES %,pattern];if(![predicate evaluateWithObject:email]){UIAlertController*alert[UIAlertController alertControllerWithTitle:注册失败message:邮箱格式不正确preferredStyle:UIAlertControllerStyleAlert];UIAlertAction*action[UIAlertAction actionWithTitle:确定style:UIAlertActionStyleDefault handler:nil];[alert addAction:action];[selfpresentViewController:alert animated:YES completion:nil];return;}NSDictionary*user{account:account,password:password};NSUserDefaults*defaults[NSUserDefaults standardUserDefaults];// 先取出原来的所有用户NSMutableArray*users[[defaults objectForKey:registeredUsers]mutableCopy];// 第一次注册时数组不存在if(!users){users[NSMutableArray array];}for(NSDictionary*dictinusers){if([dict[account]isEqualToString:account]){UIAlertController*alert[UIAlertController alertControllerWithTitle:注册失败message:账号已存在preferredStyle:UIAlertControllerStyleAlert];[alert addAction:[UIAlertAction actionWithTitle:确定style:UIAlertActionStyleDefault handler:nil]];[selfpresentViewController:alert animated:YES completion:nil];return;}}// 添加新用户[users addObject:user];// 再存回去[defaults setObject:users forKey:registeredUsers];[self.navigationController popViewControllerAnimated:YES];}-(BOOL)textField:(UITextField*)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString*)string{NSCharacterSet*charSet[[NSCharacterSet characterSetWithCharactersInString:ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.]invertedSet];//取不包含这些的字符集合用于过滤NSString*filteredStr[[string componentsSeparatedByCharactersInSet:charSet]componentsJoinedByString:];//遇到不合法的就切割最后拼接if(range.length1string.length0){//让到限定字数时也能删除字符returnYES;}elseif(textField.text.length15){textField.text[textField.text substringToIndex:15];returnNO;}elseif([string isEqualToString:filteredStr]textField.text.length15){returnYES;}returnNO;}首页对于首页的假日cell主要用到了一个双向传值也就是love按钮是否被点击对于正向采用的是属性传值对于反向则是用了一个block传值代码如下if(indexPath.row0indexPath.section0){myhomeViewController*myhome[[myhomeViewController alloc]init];myhome.loveSelectedself.firstCellLoveSelected;myhome.loveCountself.firstCellLoveCount;__weaktypeof(self)weakSelfself;myhome.loveChangedBlock^(BOOL selected,NSInteger count){weakSelf.firstCellLoveSelectedselected;weakSelf.firstCellLoveCountcount;NSIndexPath*firstIndexPath[NSIndexPath indexPathForRow:0inSection:0];[weakSelf.tableView reloadRowsAtIndexPaths:[firstIndexPath]withRowAnimation:UITableViewRowAnimationNone];};[self.navigationController pushViewController:myhome animated:YES];}}-(void)touch{self.loveSelected!self.loveSelected;if(self.loveSelected){self.loveCount1;}else{self.loveCount-1;}[selfupdateLoveButton];if(self.loveChangedBlock){self.loveChangedBlock(self.loveSelected,self.loveCount);}}在这里插入图片描述搜索页面在这里主要用了一个searchBar搜索下面是一个collection实现卡片布局,此处比较简单不多赘述上传页面在这里有几个难点首先就是这个选择图片你有两种实现方法:第一是在这个view上加手势然后跳转照片墙页面然后选择几个照片将照片回调第二个就是用苹果自带的PHpicker在此处由于练习我选择了第一种方法第二个难点则是这个折叠cell在此处我是将选中的放在第一个cell下面的四个cell是不动的这样就只用控制展开还是折叠以及被选中的label-(NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section{returnself.isExpand?self.titles.count1:1;}-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{UITableViewCell*cell[tableView dequeueReusableCellWithIdentifier:cell];if(!cell){cell[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cell];}cell.selectionStyleUITableViewCellSelectionStyleNone;cell.textLabel.font[UIFont systemFontOfSize:15];cell.textLabel.textColor[UIColor blackColor];if(indexPath.row0){cell.textLabel.textself.titles[self.selectedIndex];UIImageView*arrowView[[UIImageView alloc]initWithImage:[UIImage systemImageNamed:self.isExpand?chevron.up:chevron.down]];arrowView.tintColor[UIColor blackColor];cell.accessoryViewarrowView;}else{cell.textLabel.textself.titles[indexPath.row-1];cell.accessoryViewnil;}returncell;}-(void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath{[self.view bringSubviewToFront:self.tableView];if(indexPath.row0){self.isExpand!self.isExpand;}else{self.selectedIndexindexPath.row-1;self.isExpandNO;}CGFloat rowHeight40;NSInteger rowCountself.isExpand?self.titles.count1:1;[self.tableView mas_updateConstraints:^(MASConstraintMaker*make){make.height.mas_equalTo(rowHeight*rowCount);}];[self.tableView reloadData];}在此处还有一个textView没有placeHolder的问题此时我们需要用一个灰色的label添加在textView中并用textView的代理方法监视text一旦text不为空就将灰色label设为hidden-(void)textViewDidChange:(UITextView*)textView{self.placeholderLabel.hiddentextView.text.length0;}文章和活动页面在这里就是一个简单的分栏控件以及scrollView搭配以及TableView的使用个人页面在此处的页面比较多我就只说一些难点地方首先就是新关注页面由于不能每次打开页面都是一种关注状态所以我们需要用NSUserDefaults存储关注信息-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{followTableViewCell*followcell[tableView dequeueReusableCellWithIdentifier:cellforIndexPath:indexPath];followcell.selectionStyleUITableViewCellSelectionStyleNone;followcell.avatar.image[UIImage imageNamed:self.imageArray[indexPath.row]];followcell.name.textself.nameArray[indexPath.row];followcell.isFollow[self.isFollowArray[indexPath.row]boolValue];__weaktypeof(self)weakSelfself;followcell.followStateChanged^(BOOL isFollow){weakSelf.isFollowArray[indexPath.row](isFollow);[[NSUserDefaults standardUserDefaults]setObject:weakSelf.isFollowArray forKey:followStateArray];[weakSelf.tableview reloadRowsAtIndexPaths:[indexPath]withRowAnimation:UITableViewRowAnimationNone];};returnfollowcell;}-(void)touch{self.isFollow!self.isFollow;if(self.followStateChanged){self.followStateChanged(self.isFollow);}}其次就是私信页面私信页面需要隐藏TabBar// 隐藏tabBar-(void)viewWillAppear:(BOOL)animated{[superviewWillAppear:animated];self.tabBarController.tabBar.hiddenYES;}// 恢复tabBar-(void)viewWillDisappear:(BOOL)animated{[superviewWillDisappear:animated];self.tabBarController.tabBar.hiddenNO;}实现消息的交替发送-(void)sendClick{if(self.textField.text.length0){return;}ChatModel*model[[ChatModel alloc]init];model.contentself.textField.text;if(self.isSelf){model.typeMessageTypeSelf;}else{model.typeMessageTypeOther;}[self.dataArray addObject:model];self.isSelf!self.isSelf;NSIndexPath*indexPath[NSIndexPath indexPathForRow:self.dataArray.count-1inSection:0];[self.tableView insertRowsAtIndexPaths:[indexPath]withRowAnimation:UITableViewRowAnimationBottom];[self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];self.textField.text;}将最后一句话回传给消息列表界面保证列表显示的是聊天的最后一句话-(void)backClick{if(self.messageBlockself.dataArray.count){ChatModel*lastself.dataArray.lastObject;self.messageBlock(last.content);}[self.navigationController popViewControllerAnimated:YES];}在基本资料页面由于一开始我没有设置可编辑状态后面我用的是UIAlertController来修改资料以及用PHPicker来选择头像-(void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath{if(indexPath.row0){PHPickerConfiguration*config[[PHPickerConfiguration alloc]init];config.selectionLimit1;//只支持单选config.filter[PHPickerFilter imagesFilter];// 只显示图片PHPickerViewController*picker[[PHPickerViewController alloc]initWithConfiguration:config];picker.delegateself;[selfpresentViewController:picker animated:YES completion:nil];}if(indexPath.row1){UIAlertController*alert[UIAlertController alertControllerWithTitle:修改昵称message:nil preferredStyle:UIAlertControllerStyleAlert];[alert addTextFieldWithConfigurationHandler:^(UITextField*_Nonnull textField){textField.textself.nameText;}];UIAlertAction*confirm[UIAlertAction actionWithTitle:确定style:UIAlertActionStyleDefault handler:^(UIAlertAction*_Nonnull action){self.nameTextalert.textFields.firstObject.text;[selfsaveUserInfo];[self.tableview reloadData];}];[alert addAction:confirm];[alert addAction:[UIAlertAction actionWithTitle:取消style:UIAlertActionStyleCancel handler:nil]];[selfpresentViewController:alert animated:YES completion:nil];}if(indexPath.row2){UIAlertController*alert[UIAlertController alertControllerWithTitle:修改签名message:nil preferredStyle:UIAlertControllerStyleAlert];[alert addTextFieldWithConfigurationHandler:^(UITextField*_Nonnull textField){textField.textself.sentenceText;}];UIAlertAction*confirm[UIAlertAction actionWithTitle:确定style:UIAlertActionStyleDefault handler:^(UIAlertAction*_Nonnull action){self.sentenceTextalert.textFields.firstObject.text;[selfsaveUserInfo];[self.tableview reloadData];}];[alert addAction:confirm];[alert addAction:[UIAlertAction actionWithTitle:取消style:UIAlertActionStyleCancel handler:nil]];[selfpresentViewController:alert animated:YES completion:nil];}if(indexPath.row4){UIAlertController*alert[UIAlertController alertControllerWithTitle:修改邮箱message:nil preferredStyle:UIAlertControllerStyleAlert];[alert addTextFieldWithConfigurationHandler:^(UITextField*_Nonnull textField){textField.textself.emailText;}];UIAlertAction*confirm[UIAlertAction actionWithTitle:确定style:UIAlertActionStyleDefault handler:^(UIAlertAction*_Nonnull action){self.emailTextalert.textFields.firstObject.text;[selfsaveUserInfo];[self.tableview reloadData];}];[alert addAction:confirm];[alert addAction:[UIAlertAction actionWithTitle:取消style:UIAlertActionStyleCancel handler:nil]];[selfpresentViewController:alert animated:YES completion:nil];}if(indexPath.row3){UIAlertController*alert[UIAlertController alertControllerWithTitle:选择性别message:nil preferredStyle:UIAlertControllerStyleActionSheet];UIAlertAction*male[UIAlertAction actionWithTitle:男style:UIAlertActionStyleDefault handler:^(UIAlertAction*_Nonnull action){self.isMaleYES;[selfsaveUserInfo];[self.tableview reloadData];}];UIAlertAction*female[UIAlertAction actionWithTitle:女style:UIAlertActionStyleDefault handler:^(UIAlertAction*_Nonnull action){self.isMaleNO;[selfsaveUserInfo];[self.tableview reloadData];}];[alert addAction:male];[alert addAction:female];[alert addAction:[UIAlertAction actionWithTitle:取消style:UIAlertActionStyleCancel handler:nil]];[selfpresentViewController:alert animated:YES completion:nil];}}在这里插入图片描述

关于恒美微站

恒美微站专注于为个体商户、工作室提供极简自助建站服务,让每个人都能轻松拥有专业网站。

快速链接

  • 关于我们
  • 建站服务
  • 主题模板
  • 案例展示
  • 资讯中心

服务项目

  • 可视化建站
  • 拖拽编辑
  • 主题定制
  • SEO 优化
  • 网站托管

联系方式

  • 📍 地址:北京市朝阳区建国路 88 号
  • 📞 电话:400-888-8888
  • ✉️ 邮箱:info@hmyw.cn
  • 🕐 时间:周一至周日 9:00-18:00

© 2024 恒美微站 hmyw.cn 版权所有 | 京 ICP 备 12345678 号