ios暑假第二周--share的仿写

感悟

这周做的最累的一个项目,东西挺多的,除了前面网易云里学到的知识,还学了许多新的知识,应该也是这段时间里感觉最充足的一周时间。

多界面传值

首先在3gshare的开始界面,要求我们完成一个较为简单的登陆注册的界面,对与账号与密码的存储,我选择了NSDictionary对象,不仅仅是key和value之间一对一的关系,还有NSdictionary比较简单的遍历方法;但我们还要实现NSdictionary对象在登陆与注册两个界面之间的传递,这就要求我们去了解ios的五大传值,分别是协议传值,属性传值,block传值,通知中心传值,单例传值;主要使用的是协议传值(逆向传值),属性传值(正向传值) ;

协议传值

大致步骤如下:
第二个界面
1.创建代理协议

@protocol sortdelegate <NSObject>

- (void)presssortdelegate : (NSMutableArray*) array01 andnext : (NSMutableArray*) array02 andnext : (NSMutableArray*) array03 andnext: (NSUInteger) count ;

@end

2.创建代理类属性
@property (nonatomic) id delegate ;
第一个界面
3.传值

  [self.delegate presssortdelegate:self.array01 andnext:self.array02 andnext:self.array03 andnext:self.count] ;

第一个界面
4.遵守协议

@interface ViewController01 : UIViewController <UITableViewDelegate, UITableViewDataSource, adddelegate, deletedelegate, presschangedelegate,sortdelegate >

5.实现方法

- (void)presssortdelegate:(NSMutableArray *)array01 andnext:(NSMutableArray *)array02 andnext:(NSMutableArray *)array03 andnext:(NSUInteger)count {
    self.array01 = array01 ;
    self.array02 = array02 ;
    self.array03 = array03 ;
    self.count = count ;
    [self.tableview reloadData] ;
}
    

整体如下:

//
//  ViewController01.m
//  学生管理系统
//
//  Created by 朱敬业 on 2023/7/28.
//

#import "ViewController01.h"
#import "TableViewCell01.h"
#import "ViewControlleradd.h"
#import "ViewControllerdelete.h"
#import "findViewController.h"
#import "changeViewController.h"
#import "sortViewController.h"
@interface ViewController01 ()

@end

@implementation ViewController01

- (void)presssortdelegate:(NSMutableArray *)array01 andnext:(NSMutableArray *)array02 andnext:(NSMutableArray *)array03 andnext:(NSUInteger)count {
    self.array01 = array01 ;
    self.array02 = array02 ;
    self.array03 = array03 ;
    self.count = count ;
    [self.tableview reloadData] ;
}
    
@end
//
//  ViewController01.h
//  学生管理系统
//
//  Created by 朱敬业 on 2023/7/28.
//

#import <UIKit/UIKit.h>
#import "ViewControlleradd.h"
#import "ViewControllerdelete.h"
#import "changeViewController.h"
#import "sortViewController.h"
NS_ASSUME_NONNULL_BEGIN

@interface ViewController01 : UIViewController <UITableViewDelegate, UITableViewDataSource, adddelegate, deletedelegate, presschangedelegate,sortdelegate >
@property (nonatomic) UITableView* tableview ;
@property (nonatomic) UIButton* btn01 ;
@property (nonatomic) UIButton* btn02 ;
@property (nonatomic) UIButton* btn03 ;
@property (nonatomic) UIButton* btn04 ;
@property (nonatomic) UIButton* btn05 ;
@property (nonatomic) UIButton* btn06 ;
@property (nonatomic) UIImageView* imageview ;
@property (nonatomic) NSMutableArray* array01 ;
@property (nonatomic) NSMutableArray* array02 ;
@property (nonatomic) NSMutableArray* array03 ;
@property (nonatomic) NSUInteger count ;


@end

NS_ASSUME_NONNULL_END

#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN
@protocol sortdelegate <NSObject>

- (void)presssortdelegate : (NSMutableArray*) array01 andnext : (NSMutableArray*) array02 andnext : (NSMutableArray*) array03 andnext: (NSUInteger) count ;

@end

@interface sortViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
@property (nonatomic) NSMutableArray* array01 ;
@property (nonatomic) NSMutableArray* array02 ;
@property (nonatomic) NSMutableArray* array03 ;
@property (nonatomic) UITableView* tableview ;
@property (nonatomic) UIButton* btn01 ;
@property (nonatomic) UIButton* btn02 ;
@property (nonatomic) NSUInteger count ;
@property (nonatomic) id<sortdelegate> delegate ;
@end

NS_ASSUME_NONNULL_END



。m
  [self.delegate presssortdelegate:self.array01 andnext:self.array02 andnext:self.array03 andnext:self.count] ;

属性传值

挺简单的,直接看代码好懂些

//
//  sortViewController.h
//  学生管理系统
//
//  Created by 朱敬业 on 2023/7/29.
//

#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN
@protocol sortdelegate <NSObject>

- (void)presssortdelegate : (NSMutableArray*) array01 andnext : (NSMutableArray*) array02 andnext : (NSMutableArray*) array03 andnext: (NSUInteger) count ;

@end

@interface sortViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
@property (nonatomic) NSMutableArray* array01 ;
@property (nonatomic) NSMutableArray* array02 ;
@property (nonatomic) NSMutableArray* array03 ;
@property (nonatomic) UITableView* tableview ;
@property (nonatomic) UIButton* btn01 ;
@property (nonatomic) UIButton* btn02 ;
@property (nonatomic) NSUInteger count ;
@property (nonatomic) id<sortdelegate> delegate ;
@end

NS_ASSUME_NONNULL_END

//
//  ViewController01.m
//  学生管理系统
//
//  Created by 朱敬业 on 2023/7/28.
//
- (void)presssort {
    sortViewController* vc = [[sortViewController alloc] init] ;
    vc.count = self.count ;
    vc.array01 = self.array01 ;
    vc.array02 = self.array02 ;
    vc.array03 = self.array03 ;
    vc.delegate = self ;
    [self.navigationController pushViewController:vc animated:YES] ;
}

两者间的区别在与,协议传值把值从第二个界面传到第一个界面可以实现在第二个界面调用第一个界面,而属性传值是将值传给第二个对象使用

首页1

一个简单的无限轮播图和自定义cell,但点赞数的传值同步难了我半天,最后采用全局变量存储点赞的bool值,然后重复多次刷新tableview;
但实际上,如果对象过多,这种方法可不行;
但如果使用协议传值的话,我们有没办法传值到cell中,应为cell不是self直接拥有的属性,不能直接访问,所以那个时候没用这种方法,但实际上我们可以使用tag追踪cell,只是那时没想到;
全局变量的方法挺容以想到,我就不细说了;

//
//  ViewController01.m
//  share+ 4.18最终
//
//  Created by 朱敬业 on 2023/7/21.
//

#import "ViewController01.h"
#import "TableViewCell01.h"
#import "TableViewCell02.h"
#import "AppDelegate.h"
@interface ViewController01 ()

@end

@implementation ViewController01

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = UIColor.whiteColor ;
    self.title = @"SHARE"  ;
    //
    self.tableview = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height) style:UITableViewStyleGrouped] ;
    [self.view addSubview: self.tableview] ;
    self.tableview.delegate = self ;
    self.tableview.dataSource = self ;
    //
   
    //
    AppDelegate* mydelegate = (AppDelegate*)[UIApplication sharedApplication].delegate ;
    mydelegate.select01 = NO ;
    mydelegate.select02 = NO ;
    mydelegate.select03 = NO ;
    //
    UINavigationBarAppearance* appearance = [[UINavigationBarAppearance alloc] init] ;
    appearance.backgroundColor = [UIColor colorWithRed:79 / 255.0f green:141 / 255.0f blue:198 / 255.0f alpha:1] ;
    self.navigationController.navigationBar.standardAppearance = appearance ;
    self.navigationController.navigationBar.scrollEdgeAppearance = appearance ;
    
}


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

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

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        return 200;
    } else {
        return 150;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 0;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 15;
}

- (UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    return [[UIView alloc] init];
}

- (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    return [[UIView alloc] init];
}

- (UITableViewCell*) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    AppDelegate* mydelegate = (AppDelegate*)[UIApplication sharedApplication].delegate ;
    if (indexPath.section == 0) {
        TableViewCell01* cell = [self.tableview dequeueReusableCellWithIdentifier:@"0"] ;
        if (cell == nil) {
            cell = [[TableViewCell01 alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"0"] ;
        }
        //
        
        

        return cell;
    } else if (indexPath.section == 1 ) {
        TableViewCell02* cell = [self.tableview dequeueReusableCellWithIdentifier:@"1"] ;
        if (cell == nil) {
            cell = [[TableViewCell02 alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"1"] ;
        }
        cell.label01.text = @"假日" ;
        cell.label02.text = @"share小白" ;
        cell.label03.text = @"原创-插画-练习习作" ;
        cell.label04.text = @"十五分钟" ;
        cell.labelsee.text = @"26" ;
        cell.labelshare.text = @"20" ;
        cell.labelzan.text = [NSString stringWithFormat:@"%d",102 + mydelegate.select01] ;
        [cell.btnimage setImage:[UIImage imageNamed:@"jiari.jpg"] forState:UIControlStateNormal] ;
        [cell.btnzan addTarget:self action:@selector(pressselect01) forControlEvents:UIControlEventTouchUpInside] ;
        return cell;
    } else if (indexPath.section == 2) {
        TableViewCell02* cell = [self.tableview dequeueReusableCellWithIdentifier:@"2"] ;
        if (cell == nil) {
            cell = [[TableViewCell02 alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"2"] ;
        }
        cell.label01.text = @"原神" ;
        cell.label02.text = @"op" ;
        cell.label03.text = @"开放世界-动作冒险-椅子能坐" ;
        cell.label04.text = @"十六分钟" ;
        [cell.btnimage setImage:[UIImage imageNamed:@"yuanshen.jpeg"] forState:UIControlStateNormal] ;
        cell.labelsee.text = @"26" ;
        cell.labelshare.text = @"20" ;
        cell.labelzan.text = [NSString stringWithFormat:@"%d",124 + mydelegate.select02] ;
        [cell.btnzan addTarget:self action:@selector(pressselect02) forControlEvents:UIControlEventTouchUpInside] ;
        return cell;
    } else {
        TableViewCell02* cell = [self.tableview dequeueReusableCellWithIdentifier:@"3"] ;
        if (cell == nil) {
            cell = [[TableViewCell02 alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"3"] ;
        }
        cell.label01.text = @"DDDDecade" ;
        cell.label02.text = @"小明哥" ;
        cell.label03.text = @"我只是一个路过的卡面来打" ;
        cell.label04.text = @"十六分钟" ;
        [cell.btnimage setImage:[UIImage imageNamed:@"decade.jpg"] forState:UIControlStateNormal] ;
        cell.labelsee.text = @"26" ;
        cell.labelshare.text = @"20" ;
        cell.labelzan.text = [NSString stringWithFormat:@"%d",138 + mydelegate.select03] ;
        [cell.btnzan addTarget:self action:@selector(pressselect03) forControlEvents:UIControlEventTouchUpInside] ;
        return cell;
    }
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 1) {
        self.vc01 = [[ViewController010 alloc] init] ;
        [self.navigationController pushViewController:self.vc01 animated:YES] ;
        NSLog(@"hello") ;
    } else if (indexPath.section == 2) {
        self.vc02 = [[ViewController011 alloc] init] ;
        [self.navigationController pushViewController:self.vc02 animated:YES] ;
    } else if (indexPath.section == 3) {
        self.vc03 = [[ViewController012 alloc] init] ;
        [self.navigationController pushViewController:self.vc03 animated:YES] ;
    }
}

- (void)pressselect01  {
    AppDelegate* mydelegate = (AppDelegate*)[UIApplication sharedApplication].delegate ;
    if (mydelegate.select01 == YES) {
        mydelegate.select01 = NO ;
    } else {
        mydelegate.select01 = YES ;
    }
    [self.tableview reloadData] ;
}

- (void)pressselect02 {
    AppDelegate* mydelegate = (AppDelegate*)[UIApplication sharedApplication].delegate ;
    if (mydelegate.select02 == YES) {
        mydelegate.select02 = NO ;
    } else {
        mydelegate.select02 = YES ;
    }
    [self.tableview reloadData] ;
}

- (void)pressselect03 {
    AppDelegate* mydelegate = (AppDelegate*)[UIApplication sharedApplication].delegate ;
    if (mydelegate.select03 == YES) {
        mydelegate.select03 = NO ;
    } else {
        mydelegate.select03 = YES ;
    }
    [self.tableview reloadData] ;
}

- (void)viewWillAppear:(BOOL)animated {
    [self.tableview reloadData] ;
}

@end

//
//  AppDelegate.h
//  share+ 4.18最终
//
//  Created by 朱敬业 on 2023/7/21.
//

#import <UIKit/UIKit.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (nonatomic) BOOL select01 ;
@property (nonatomic) BOOL select02 ;
@property (nonatomic) BOOL select03 ;
@property (nonatomic) BOOL selectxinbie ;
@property (nonatomic) BOOL select1 ;
@property (nonatomic) BOOL select2 ;
@property (nonatomic) BOOL select3 ;
@property (nonatomic) BOOL select4 ;
@property (nonatomic) BOOL select5 ;
@property (nonatomic) BOOL select04 ;
@property (nonatomic) BOOL select05 ;
@property (nonatomic) BOOL select06 ;
//代理类全局变量
@end


//
//  ViewController010.m
//  share+ 4.18最终
//
//  Created by 朱敬业 on 2023/7/22.
//

#import "ViewController010.h"
#import "AppDelegate.h"
#import "TableViewCellNew.h"
@interface ViewController010 ()

@end

@implementation ViewController010

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = UIColor.whiteColor ;
    self.scrollview = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)] ;
    self.scrollview.pagingEnabled = NO ;
    self.scrollview.scrollEnabled = YES ;
    self.scrollview.contentSize = CGSizeMake(self.view.bounds.size.width, self.view.bounds.size.height * 3) ;
    self.scrollview.contentOffset = CGPointMake(0, 0) ;
    [self.view addSubview:self.scrollview] ;
    //
    self.tableview = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 90)] ;
    self.tableview.delegate = self ;
    self.tableview.dataSource = self ;
    [self.tableview setScrollEnabled:NO] ;
    [self.scrollview addSubview:self.tableview] ;

//
//
//    self.labelsee.text = @"26" ;
//    self.labelshare.text = @"20" ;
//    //
    self.label04 = [[UILabel alloc] initWithFrame:CGRectMake(10, 110, self.view.bounds.size.width, 10)] ;
    self.label04.text = @"多希望列车能把我带到有你的城市" ;
    self.label04.font = [UIFont systemFontOfSize:10] ;
    [self.scrollview addSubview:self.label04] ;
    //
    UIImageView* imageview01 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"works_img1.png"]] ;
    imageview01.frame = CGRectMake(10, 130, self.view.bounds.size.width - 20, 220) ;
    [self.scrollview addSubview:imageview01] ;
    UIImageView* imageview02 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"works_img2.png"]] ;
    imageview02.frame = CGRectMake(10, 360, self.view.bounds.size.width - 20, 220) ;
    [self.scrollview addSubview:imageview02] ;
    UIImageView* imageview03 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"works_img3.png"]] ;
    imageview03.frame = CGRectMake(95, 590, 200, 280) ;
    [self.scrollview addSubview:imageview03] ;
    UIImageView* imageview04 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"works_img4.png"]] ;
    imageview04.frame = CGRectMake(10, 880, self.view.bounds.size.width - 20, 220) ;
    [self.scrollview addSubview:imageview04] ;
    UIImageView* imageview05 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"works_img5.png"]] ;
    imageview05.frame = CGRectMake(95, 1110, 200, 280) ;
    [self.scrollview addSubview:imageview05] ;
}

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

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

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

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 0;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 0;
}

- (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    return [UIView new];
}

- (UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    return [UIView new];
}

- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    AppDelegate* mydelegate = (AppDelegate*)[UIApplication sharedApplication].delegate ;
    TableViewCellNew* cell = [self.tableview dequeueReusableCellWithIdentifier:@"0"] ;
    if (cell == nil) {
        cell = [[TableViewCellNew alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"0"] ;
    }
    cell.label01.text = @"假日" ;
    cell.label02.text = @"share小白" ;
    cell.label03.text = @"原创-插画-练习习作" ;
    cell.label04.text = @"十五分钟" ;
    cell.labelzan.text = [NSString stringWithFormat:@"%d",102 + mydelegate.select01] ;
    cell.labelsee.text = @"26" ;
    cell.labelshare.text = @"20" ;
    [cell.btnimage setImage:[UIImage imageNamed:@"jiari.jpg"] forState:UIControlStateNormal] ;
    [cell.btnzan addTarget:self action:@selector(pressselect01) forControlEvents:UIControlEventTouchUpInside] ;
    return cell;
}

- (void)viewWillAppear:(BOOL)animated {
    [self.tableview reloadData] ;
}



/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
- (void)pressselect01  {
    AppDelegate* mydelegate = (AppDelegate*)[UIApplication sharedApplication].delegate ;
    if (mydelegate.select01 == YES) {
        mydelegate.select01 = NO ;
    } else {
        mydelegate.select01 = YES ;
    }
    [self.tableview reloadData] ;
    
}




@end

搜索2

该界面的在于照片墙传值和折叠cell这两个弄了好久
照片墙的传值要将选中的照片和数量同时穿过去,且必须在点击按钮后穿过去,这意味着要将所有的照片遍历是否选中,但我们不能真的给每个照片创建一个🆕的对象名来访问,那样代码量太大了;
所以这里用到了循环创建和tag追踪来缩小代码量;
折叠cell的话不是很难,用一个按钮来改变tableview 的大小和cell数量,通过NsArray来存储数据,再通过点击cell改变NSArray顺序 ;

//
//  ViewControllerzhaopianqiang.m
//  share+ 4.18最终
//
//  Created by 朱敬业 on 2023/7/25.
//

#import "ViewControllerzhaopianqiang.h"

@interface ViewControllerzhaopianqiang ()

@end

@implementation ViewControllerzhaopianqiang

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = UIColor.whiteColor ;
    self.scrollview = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)] ;
    self.scrollview.scrollEnabled = YES ;
    self.scrollview.pagingEnabled = NO ;
    self.scrollview.contentSize = CGSizeMake(self.view.bounds.size.width, self.view.bounds.size.height * 2) ;
    self.scrollview.contentOffset = CGPointMake(0, 0) ;
    for (int i = 0; i < 15; i++) {
        NSString* str = [NSString stringWithFormat:@"%d.jpeg",i + 1] ;
        UIImage* image = [UIImage imageNamed:str] ;
        UIImageView* imageview = [[UIImageView alloc] initWithImage:image] ;
        imageview.frame = CGRectMake((i % 3) * 127, 2 + (i / 3) * 127, 125, 125) ;
        [self.scrollview addSubview:imageview] ;
        UIButton* btnimage = [UIButton buttonWithType:UIButtonTypeCustom] ;
        btnimage.selected = NO ;
        btnimage.frame = CGRectMake((i % 3) * 127, 2 + (i / 3) * 127, 125, 125) ;
        [btnimage addTarget:self action:@selector(presstap:) forControlEvents:UIControlEventTouchUpInside] ;
        [self.scrollview addSubview:btnimage] ;
        btnimage.tag = 101 + i ;
        
    }
    [self.view addSubview:self.scrollview] ;
    //
    self.btnright = [[UIBarButtonItem alloc] initWithTitle:@"上传" style:UIBarButtonItemStylePlain target:self action:@selector(pressshangchuan)] ;
    self.navigationItem.rightBarButtonItem = self.btnright ;
}

- (void)presstap : (UIButton*) btnimage  {
    if (btnimage.selected == NO) {
        btnimage.selected = YES ;
        UIImageView* imageview = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"my_button_pressed.png"]] ;
        imageview.frame = CGRectMake(90, 5, 30, 30) ;
        [btnimage addSubview:imageview] ;
    } else {
        btnimage.selected = NO ;
        [btnimage.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)] ;
    }
}

- (void)pressshangchuan {
    UIAlertController* alertcintroller = [UIAlertController alertControllerWithTitle:@"提示" message:@"确认上传所选内容" preferredStyle:UIAlertControllerStyleAlert] ;
    UIAlertAction* action01 = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        UIButton* btnimage  ;
        NSString* str ;
        int count = 0 ;
        for (int i = 0; i < 15 ; i++) {
            btnimage = (UIButton*)[self.view viewWithTag:101 + i] ;
            if (btnimage.selected == YES) {
                count ++;
                 str = [NSString stringWithFormat:@"%d.jpeg",i + 1] ;
            }
        }
        [self.delegate pressstr:str Andcount:count] ;
        NSLog(@"%@ %d",str,count) ;
        [self.navigationController popViewControllerAnimated:YES] ;
    }] ;
    UIAlertAction* action02 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
    }] ;
    [alertcintroller addAction:action01] ;
    [alertcintroller addAction:action02] ;
    [self presentViewController:alertcintroller animated:YES completion:nil] ;
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end

 self.btnzhedie = [UIButton buttonWithType:UIButtonTypeCustom] ;
    [self.btnzhedie setImage:[UIImage imageNamed:@"up.png"] forState:UIControlStateNormal] ;
    [self.btnzhedie addTarget:self action:@selector(presszhedie) forControlEvents:UIControlEventTouchUpInside] ;
    self.btnzhedie.frame = CGRectMake(250, 200, 20, 20) ;
    [self.view addSubview:self.btnzhedie] ;
    //
    self.tableview01 = [[UITableView alloc] initWithFrame:CGRectMake(280, 205, 100, 30) style:UITableViewStylePlain] ;
    self.tableview01.delegate = self ;
    self.tableview01.dataSource = self ;
    self.tableview01.tag = 101 ;
    
    [self.view addSubview:self.tableview01] ;
    
    
    self.label01 = [[UILabel alloc] init] ;
    self.label01.backgroundColor = UIColor.redColor ;
    self.label01.textColor = UIColor.whiteColor ;
    self.label01.frame = CGRectMake(230, 100, 20, 20) ;
    self.label01.text = [NSString stringWithFormat:@"%d",self.count] ;
    [self.view addSubview:self.label01] ;
//
//    self.tableview01.scrollEnabled = NO ;
    self.array = [NSMutableArray arrayWithObjects:@"原创作品", @"设计资料", @"设计师观点", @"设计教程", nil] ;
    self.label02 = [[UILabel alloc] initWithFrame:CGRectMake(280, 205, 100, 30)] ;
    [self.view addSubview:self.label02] ;
    self.label02.textAlignment = NSTextAlignmentCenter ;
    self.label02.text = self.array[0] ;
    self.label02.backgroundColor = UIColor.whiteColor ;



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

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (tableView.tag == 101) {
        return 1;
    } else {
        return 4;
    }
}

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

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 0;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 0;
}

- (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    return [UIView new];
}

- (UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    return [UIView new];
}

- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell* cell = [self.tableview01 dequeueReusableCellWithIdentifier:@"0"] ;
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"0"] ;
    }
    cell.textLabel.font = [UIFont systemFontOfSize:15] ;
    for (int i = 0; i < 4;i ++ ) {
        if (indexPath.row == i) {
            cell.textLabel.text  = self.array[i] ;
        }
        
    }
    
    
    

        return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    NSString* str = [NSString stringWithString:[tableView cellForRowAtIndexPath:indexPath].textLabel.text ] ;
    self.label02.text = str ;
    for (int i = 0; i < 4; i++) {
        if (self.array[i] == str)  {
            self.array[i] = self.array[0] ;
            self.array[0] = str ;
        }
    }
    NSLog(@"jj") ;
    [self.tableview01 reloadData] ;
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end

文章3

乍一看很难,其实就是滚动视图上套三个单元格;
但要注意tableview开启可滑动后,也会调用scrollerview的协议函数;

活动4

就是自定义cell

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值