前言
本周进行了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;
效果图:

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

被折叠的 条评论
为什么被折叠?



