• 循环&信息添加&颜色修改


           

    #import "AViewController.h"

     

    @interface AViewController () <UIActionSheetDelegate>

     

    @end

     

    @implementation AViewController

     

    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

    {

        self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

        if (self) {

            

        }

        return self;

    }

    - (void)viewDidLoad

    {

        [super viewDidLoad];

        // Do any additional setup after loading the view.

        

        self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"下一页" style:UIBarButtonItemStyleDone target:self action:@selector(nextClick)];

    }

     

    - (void)nextClick

    {

        int num = self.navigationController.viewControllers.count+1;

        int r = arc4random_uniform(256);

        int g = arc4random_uniform(256);

        int b = arc4random_uniform(256);

        

        AViewController *av = [[AViewController alloc]init];

        av.navigationItem.title = [NSString stringWithFormat:@"第%d页",num];

        av.view.backgroundColor = [UIColor colorWithRed:r/255.0f green:g/255.0f blue:b/255.0f alpha:1];

        av.hidesBottomBarWhenPushed = YES;

        av.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"返回" style:UIBarButtonItemStyleDone target:av action:@selector(backClick)];

        [self.navigationController pushViewController:av animated:YES];

    }

     

    - (void)backClick

    {

        UIActionSheet *as = [[UIActionSheet alloc]initWithTitle:@"返回到" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"首页" otherButtonTitles:@"上一页",@"第三页",@"第五页", nil];

        [as showInView:self.tabBarController.view];

    }

     

    - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex

    {

        NSArray *arr = self.navigationController.viewControllers;

        

        switch (buttonIndex) {

            case 0:

            {

                [self.navigationController popToRootViewControllerAnimated:YES];

            }

                break;

            case 1:

            {

                [self.navigationController popViewControllerAnimated:YES];

            }

                break;

            case 2:

            {

                if (arr.count > 2) {

                    [self.navigationController popToViewController:[arr objectAtIndex:2] animated:YES];

                }

            }

                break;

            case 3:

            {

                if (arr.count > 4) {

                    [self.navigationController popToViewController:[arr objectAtIndex:4] animated:YES];

                }

            }

                break;

            default:

                break;

        }

    }

     

    - (void)didReceiveMemoryWarning

    {

        [super didReceiveMemoryWarning];

        // Dispose of any resources that can be recreated.

    }

     

    @end

     

     

     

     

     

     

     

     

     

     

     

     

    #import "BViewController.h"

    #import "CViewController.h"

     

    @interface BViewController ()

     

    @end

     

    @implementation BViewController

     

    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

    {

        self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

        if (self) {

            // Custom initialization

        }

        return self;

    }

     

    - (void)viewDidLoad

    {

        [super viewDidLoad];

        // Do any additional setup after loading the view from its nib.

    }

     

    //保存按钮点击事件

    - (IBAction)saveClick:(UIButton *)sender

    {

        [self.view endEditing:YES];

        

        UITextField *name = (UITextField *)[self.view viewWithTag:1];

        UITextField *age = (UITextField *)[self.view viewWithTag:2];

        UITextField *num = (UITextField *)[self.view viewWithTag:3];

        

        NSString *str = [NSString stringWithFormat:@"姓名:%@ 年龄:%@ 成绩:%@",name.text,age.text,num.text];

        

        CViewController *cv = [self.tabBarController.viewControllers objectAtIndex:2];

        [cv.dataArr addObject:str];

    }

     

    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

    {

        [self.view endEditing:YES];

    }

     

    - (void)didReceiveMemoryWarning

    {

        [super didReceiveMemoryWarning];

        // Dispose of any resources that can be recreated.

    }

     

     

     

     

     

     

     

     

     

     

     

     

    #import <UIKit/UIKit.h>

     

    @interface CViewController : UIViewController

     

    @property (nonatomic,retain)NSMutableArray *dataArr;

     

    @end

     

     

     

     

     

     

     

     

     

     

     

     

     

    #import "CViewController.h"

    #import "AppDelegate.h"

     

    @interface CViewController () <UITableViewDataSource,UITableViewDelegate>

     

    {

        UITableView *_myTableView;

    }

     

    @end

     

    @implementation CViewController

     

    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

    {

        self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

        if (self) {

            // Custom initialization

            _dataArr = [[NSMutableArray alloc]init];

        }

        return self;

    }

     

    - (void)viewWillAppear:(BOOL)animated

    {

        [_myTableView reloadData];

    }

     

    - (void)viewDidLoad

    {

        [super viewDidLoad];

        // Do any additional setup after loading the view.

        

        _myTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 40, 320, [UIScreen mainScreen].bounds.size.height-49-40)];

        _myTableView.delegate = self;

        _myTableView.dataSource = self;

        [self.view addSubview:_myTableView];

    }

     

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

    {

        return _dataArr.count;

    }

     

    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

    {

        return 80;

    }

     

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

    {

        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"qqq"];

        if (!cell) {

            cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"qqq"];

            

            UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 320, 80)];

            label.numberOfLines = 0;

            label.backgroundColor = [UIColor yellowColor];

            label.tag = 1;

            [cell.contentView addSubview:label];

        }

        

        UILabel *la = (UILabel *)[cell.contentView viewWithTag:1];

        la.text = [_dataArr objectAtIndex:indexPath.row];

        

        return cell;

    }

     

    - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath

    {

        [_dataArr removeObjectAtIndex:indexPath.row];

        [_myTableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];

    }

     

     

    - (void)didReceiveMemoryWarning

    {

        [super didReceiveMemoryWarning];

        // Dispose of any resources that can be recreated.

    }

     

     

     

     

     

     

     

     

     

     

     

     

     

    #import "DViewController.h"

     

    @interface DViewController () <UIScrollViewDelegate>

     

    {

        UIScrollView *_sview1;

        UIScrollView *_sview2;

        UIScrollView *_sview3;

    }

     

    @end

     

    @implementation DViewController

     

    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

    {

        self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

        if (self) {

            // Custom initialization

        }

        return self;

    }

     

    - (void)viewDidLoad

    {

        [super viewDidLoad];

        // Do any additional setup after loading the view.

        

        _sview1 = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 40, 320, 120)];

        _sview1.pagingEnabled = YES;

        _sview1.delegate = self;

        _sview1.backgroundColor = [UIColor redColor];

        _sview1.contentSize = CGSizeMake(320*10, 120);

        for (int i = 0; i<10; i++) {

            UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(i*320, 0, 320, 120)];

            label.text = [NSString stringWithFormat:@"%i只青蛙",i+1];

            label.textAlignment = NSTextAlignmentCenter;

            [_sview1 addSubview:label];

        }

        [self.view addSubview:_sview1];

        

        _sview2 = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 170, 320, 120)];

        _sview2.backgroundColor = [UIColor yellowColor];

        _sview2.delegate = self;

        _sview2.pagingEnabled = YES;

        _sview2.contentSize = CGSizeMake(320*20, 120);

        for (int i = 0; i<20; i++) {

            UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(i*320, 0, 320, 120)];

            label.text = [NSString stringWithFormat:@"%i只公鸡",i+1];

            label.textAlignment = NSTextAlignmentCenter;

            [_sview2 addSubview:label];

        }

        [self.view addSubview:_sview2];

        

        _sview3 = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 300, 320, 120)];

        _sview3.backgroundColor = [UIColor brownColor];

        _sview3.pagingEnabled = YES;

        _sview3.delegate = self;

        _sview3.scrollEnabled = NO;

        _sview3.contentSize = CGSizeMake(320*40, 120);

        for (int i=0; i<41;i++) {

            UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(i*320, 0, 320, 120)];

            label.text = [NSString stringWithFormat:@"%i条腿",i];

            label.textAlignment = NSTextAlignmentCenter;

            [_sview3 addSubview:label];

        }

        [self.view addSubview:_sview3];

    }

     

    - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView

    {

        int a = scrollView.contentOffset.x/320 + 1;

        

        if (scrollView==_sview1) {

            [_sview3 setContentOffset:CGPointMake(a*320*4, 0)animated:YES];

        } else {

            [_sview3 setContentOffset:CGPointMake(a*320*2, 0) animated:YES];

        }

    }

     

    - (void)didReceiveMemoryWarning

    {

        [super didReceiveMemoryWarning];

        // Dispose of any resources that can be recreated.

    }

     

     

     

     

     

     

     

     

     

     

     

     

     

    #import "EViewController.h"

     

    @interface EViewController ()

     

    @end

     

    @implementation EViewController

     

    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

    {

        self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

        if (self) {

            // Custom initialization

        }

        return self;

    }

     

    - (void)viewDidLoad

    {

        [super viewDidLoad];

        // Do any additional setup after loading the view from its nib.

    }

     

    //slider滑动事件

    - (IBAction)colorChange:(UISlider *)sender

    {

        UISlider *s1 = (UISlider *)[self.view viewWithTag:11];

        UISlider *s2 = (UISlider *)[self.view viewWithTag:12];

        UISlider *s3 = (UISlider *)[self.view viewWithTag:13];

        

        self.view.backgroundColor = [UIColor colorWithRed:s1.value green:s2.value blue:s3.value alpha:1];

    }

     

    //保存按钮点击事件

    - (IBAction)saveClick:(UIButton *)sender

    {

        for (UIViewController *vc in self.tabBarController.viewControllers) {

            vc.view.backgroundColor = self.view.backgroundColor;

        }

    }

     

    - (void)didReceiveMemoryWarning

    {

        [super didReceiveMemoryWarning];

        // Dispose of any resources that can be recreated.

    }

     

    @end

     

     

     

     

     

     

     

     

     

     

     

     

     

    #import "MyTabBar.h"

    #import "AViewController.h"

    #import "BViewController.h"

    #import "CViewController.h"

    #import "DViewController.h"

    #import "EViewController.h"

     

     

    @interface MyTabBar ()

     

    @end

     

    @implementation MyTabBar

     

    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

    {

        self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

        if (self) {

            // Custom initialization

        }

        return self;

    }

     

    - (void)viewDidLoad

    {

        [super viewDidLoad];

        // Do any additional setup after loading the view.

        AViewController *av = [[AViewController alloc]init];

        BViewController *bv = [[BViewController alloc]init];

        CViewController *cv = [[CViewController alloc]init];

        DViewController *dv = [[DViewController alloc]init];

        EViewController *ev = [[EViewController alloc]init];

        av.title = @"首页";

        bv.title = @"添加";

        cv.title = @"联系人";

        dv.title = @"动态";

        ev.title = @"设置";

        

        UINavigationController *an = [[UINavigationController alloc]initWithRootViewController:av];

        

        NSArray *controllers = [NSArray arrayWithObjects:an,bv,cv,dv,ev, nil];

        self.viewControllers = controllers;

        

    }

     

    - (void)didReceiveMemoryWarning

    {

        [super didReceiveMemoryWarning];

        // Dispose of any resources that can be recreated.

    }

     

    让明天,不后悔今天的所作所为
  • 相关阅读:
    [实验]虚拟局域网vlan
    微信小程序配置文件详解
    关于MySQL与Ubuntu 以及不同系统更新补丁的方式
    Windows使用scrcpy局域网无线操作Android手机
    IDEA 使用技巧
    在Ubuntu上对apache的卸载操作
    Android两种按钮点击事件触发方式 和 一些简单的布局
    Inkscape 自由画图:https://inkscape.org/zhhans/about/
    测试通过的标准
    bug回归注意事项
  • 原文地址:https://www.cnblogs.com/-yun/p/4379173.html
Copyright © 2020-2023  润新知