zoukankan      html  css  js  c++  java
  • ObjecticeC之方法、消息和选择器

      在第一篇Car的方法中加入一个类方法:

    + (NSString *) motto
    {
    return(@"Ford Prefects are Mostly Harmless");
    }
    #import <UIKit/UIKit.h>
    #import "Car.h"

    //统一定义颜色和button风格
    #define COOKBOOK_PURPLE_COLOR [UIColor colorWithRed:0.20392f green:0.19607f blue:0.61176f alpha:1.0f]
    #define BARBUTTON(TITLE, SELECTOR) [[[UIBarButtonItem alloc] initWithTitle:TITLE style:UIBarButtonItemStylePlain target:self action:SELECTOR] autorelease]

    //定义TestBedViewController控制器
    @interface TestBedViewController : UIViewController
    @end

    //实现控制器
    @implementation TestBedViewController
    //定义函数
    - (void) action: (id) sender
    {
    // Calling a class method
    NSLog(@"%@", [Car motto]);//调用类函数
    }

    - (void) viewDidLoad
    {
    self.navigationController.navigationBar.tintColor = COOKBOOK_PURPLE_COLOR;
    self.navigationItem.rightBarButtonItem = BARBUTTON(@"Action", @selector(action:));//设定右边导航栏的按钮的标题和事件
    //此处@selector表示选择器
    }
    @end



  • 相关阅读:
    数组的顺序存储表示
    CF538G Berserk Robot
    【LGR-077】洛谷 10 月月赛 I Div.1 && P6854 Tram
    [THUPC2019]找树
    CF536D Tavas in Kansas
    luogu「EZEC-4.5」子序列
    2020.8.7
    拉格朗日反演
    2020.8.6
    初赛复习
  • 原文地址:https://www.cnblogs.com/foxmin/p/2413093.html
Copyright © 2011-2022 走看看