OC中 子控件 传递方法几种方案

用户行为数据分析 User Behavior Data from Taobao for Recommendation 一、提出问题 二、理解数据 数据来源 阿里云天池数据集:(https://tianchi.aliyun.com/dataset/dataDetail?dataId=649) 本文选取的数据集为UserBehavior.csv,共有5242880条数据。数据的具体类别如下表所示: 用户行为种类有四种,如下表所示 对于数据维度的说明如下: 在本文选取的2017年11月25日到2017年12月3日的时间范围内,不重复的用户数量为10202,不重复的商品ID数为412369,不重复的商品类目ID数为5859, 阅读详情

前言:最近刚刚结束一个项目,身心疲惫,还是得写写项目中用到的一些常见数据传递方案。

一、一对一方案

001 代理

通过一个子控件定义几个协议函数在父控件的 @interface ()<协议> 继承该代理,在父控件中实现这些函数,最经典就是UITableView的实现方式。要注意某些代理是否是required关键词声明了required关键词就得必须实现否则会报错

002 block

子控件声明block函数,在父控件中,子控件通过setBlock方法可以将子控件的参数传给父控件来进行使用,但是block使用特别要注意循环引用的风险,解决方案就是使用weakSelf关键字,这样就可以避免循环引用。子控件可以通过判断该block方法是否为空再执行该block方法。如果block中要进行UI刷新操作就得在主线程中进行操作,否则数据不会及时在UI中刷新出来。

#define WS(weakSelf)  __weak __typeof(&*self)weakSelf = self;

003 runtime 设置forward关键字 将子控件执行的某方法通过runtime的动态解析将方法具体执行的对象只想父控件。

- (id)forwarder{
    return objc_getAssociatedObject(self, @selector(forwarder));
}

- (void)setForwarder:(id)forwarder{
    objc_setAssociatedObject(self, @selector(forwarder), forwarder, OBJC_ASSOCIATION_ASSIGN);
}

- (id)forwardingTargetForSelector:(SEL)aSelector{
    
    return self.forwarder;
}

二、一对多方案

001 NSNotification通知 

可以举个场景:一个父控件中有几个子控件。子控件1操作会让子控件2进行数据刷新操作,具体的场景就是购物车 待付款栏目的商品付款完成之后,会在待收货栏目显示出来,

 [[NSNotificationCenter defaultCenter] postNotificationName:HomeListRefreshNotificationName object:nil];

- (void)registerNotifications{
    
    [[NSNotificationCenter  defaultCenter] addObserver:self selector:@selector(homeVCDidAppear) name:HomeListRefreshNotificationName object:nil];
}

- (void)removeNotifications{
    [[NSNotificationCenter  defaultCenter] removeObserver:self name:HomeListRefreshNotificationName object:nil];
}

002 KVO 监听某个控件状态变化


#pragma mark - KVO
- (void)zy_addObserver
{
    [self addObserver:self forKeyPath:@"attributedText" options:(NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld) context:nil];
}
- (void)zy_removeObserver
{
    id info = self.observationInfo;
    NSString * key = @"attributedText";
    NSArray *array = [info valueForKey:@"_observances"];
    for (id objc in array) {
        id Properties = [objc valueForKeyPath:@"_property"];
        NSString *keyPath = [Properties valueForKeyPath:@"_keyPath"];
        if ([key isEqualToString:keyPath]) {
            [self removeObserver:self forKeyPath:@"attributedText" context:nil];
        }
    }
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context
{
    if ([keyPath isEqualToString:@"attributedText"]) {
        if (self.isTapAction) {
            if (![change[NSKeyValueChangeNewKey] isEqual: change[NSKeyValueChangeOldKey]]) {
            }
        }
    }
}

三、全局方法

001 单例模式

例如商品筛选页面提交的参数和具体刷新的页面不在同一个模块,这样就得用单例模式将筛选的参数,保留起来在该刷新的页面拿到该筛选的参数进行网络接口请求

#define SingletonH(name)    + (instancetype)shared##name

#if __has_feature(objc_arc)

#define SingletonM(name)                            \
\
static id instance;                                 \
\
+ (instancetype)shared##name                        \
{                                                   \
static dispatch_once_t onceToken;               \
dispatch_once(&onceToken, ^{                    \
instance = [[self alloc] init];             \
});                                             \
\
return instance;                                \
}                                                   \
\
+ (instancetype)allocWithZone:(NSZone *)zone        \
{                                                   \
static dispatch_once_t onceToken;               \
dispatch_once(&onceToken, ^{                    \
instance = [super allocWithZone:zone];      \
});                                             \
return instance;                                \
}                                                   \
\
- (id)copyWithZone:(NSZone *)zone                   \
{                                                   \
return self;                                    \
}

#else
#define SingletonM(name)                            \
\
static id instance;                                 \
\
+ (instancetype)shared##name                        \
{                                                   \
static dispatch_once_t onceToken;               \
dispatch_once(&onceToken, ^{                    \
instance = [[self alloc] init];             \
});                                             \
\
return instance;                                \
}                                                   \
\
+ (instancetype)allocWithZone:(NSZone *)zone        \
{                                                   \
static dispatch_once_t onceToken;               \
dispatch_once(&onceToken, ^{                    \
instance = [super allocWithZone:zone];      \
});                                             \
return instance;                                \
}                                                   \
\
- (id)copyWithZone:(NSZone *)zone                   \
{                                                   \
return self;                                    \
}                                                   \
\
- (instancetype)autorelease                         \
{                                                   \
return self;                                    \
}                                                   \
\
- (instancetype)retain                              \
{                                                   \
return self;                                    \
}                                                   \
\
- (NSUInteger)retainCount                           \
{                                                   \
return 1;                                       \
}                                                   \
\
- (oneway void)release                              \
{                                                   \
\
}
#endif

四、总结

在项目中上述方案适用不同的需求场景,具体问题具体分析,多样化操作实现需求,可以让程序更加健壮。

 

OpenHarmony电源管理驱动架构剖析:HDI框架下的低功耗实现 鸿蒙电源管理驱动模块是OpenHarmony操作系统中负责设备电源状态管理的核心组件。该模块基于HDI(Hardware Device Interface)框架实现,提供了完整的电源管理功能,包括系统休眠/唤醒、运行锁管理、休眠模式控制等核心功能。public:// 主要接口函数// 运行锁管理private:// 内部辅助函数// 成员变量public:// 运行锁控制接口// 回调管理private:// 内部辅助函数。 阅读详情

相关推荐

Halcon实战:5分钟搞定灰度图转热力图(附完整代码)

本文提供了一份Halcon实战指南,详细讲解如何在5分钟内将灰度图转换为直观的热力图。通过核心代码演示了利用HSV颜色模型进行色彩映射的原理与步骤,包括图像归一化、通道构建与空间转换,并附赠了深度图可视化等进阶应用技巧,帮助工程师快速提升图像分析效果。

weixin_29240343的博客 282

【转】iOS笔记-自定义控件(OC)

原文网址:http://www.jianshu.com/p/f23862eb7b8a 导读: iOS开发中,很多时候系统提供的控件并不能很好的满足我们的需求,因此,自定义控件便成为搭建UI界面中必不可少的一部分。本篇博文以笔记的形式,总结了自定义控件的两种方式以及每种方式的实现步骤,虽简略却不简单,因此希望留给读者更多的思考空间。作为入门的编程学习者,独立思考能力和动手编程能力都是至关重要的。在...

weixin_34235135的博客 286

dify工作流的原理

摘要: Dify 工作流是一个基于有向无环图(DAG)的智能任务编排系统,支持多节点(如LLM调用、API工具、条件分支等)的可视化拖拽与流程编排。其核心原理包括执行引擎(解析DAG并管理节点依赖)、上下文变量传递(类Jinja模板的变量引用机制)和状态持久化(存储执行日志与中间结果)。工作流通过事件驱动执行,支持异步任务调度,并与RAG知识库、LLM服务等模块深度集成,最终可发布为API或对话应用。技术栈基于Python(FastAPI+Celery)和PostgreSQL,实现低代码化的AI应用开发。

nbspzs的专栏 2187

80_iOS干货43_调用OC方法传递多个参数的11种方法

一,方法中写多个参数调用 - (void)test1 { [self testFunctionWithParams1:6 :@"234131#"]; } - (void)testFunctionWithParams1:(int )number :(NSString *)string { NSLog(@"方法多个参数:%i%@",number, string); } 二,per...

a_horse的博客 3496

从零开始:如何用Python手绘波特图并分析电路稳定性

本文详细介绍了如何使用Python绘制波特图并分析电路稳定性,涵盖从基础理论到实际应用的完整流程。通过NumPy和Matplotlib实现频域分析,包括RC低通滤波器和RLC带通滤波器的案例,以及相位裕度计算等高级技巧,为电子工程师提供了一套高效的电路分析解决方案。

hhh00的博客 371

手把手教你用Boot-Repair快速修复Ubuntu启动分区缺失(附详细命令行步骤)

本文详细介绍了如何使用Boot-Repair工具快速修复Ubuntu启动分区缺失问题,包括诊断、应急准备、自动修复和手动命令操作。通过grub rescue模式下的关键命令和Boot-Repair的图形界面操作,帮助用户高效解决启动分区故障,确保系统恢复正常运行。

weixin_29229989的博客 563

oc基础入门之指针在方法间的传递

一代码引入 int main(){ NSString *s = @"456"; test(s); return 0; } void test(NSString *str){ str = @"123"; }

lskshz的专栏 1170

abaqus单位设置_ABAQUS热辐射分析实例

热辐射是一种通过电磁波传递热能的方式。电磁波以光的速度进行传递,而能量传递与辐射物体之间的介质无关。热辐射只在电磁波的频谱中占小部分的带宽。由于辐射产生的热流与物体表面的绝对温度的四次方成正比因此热辐射有限元分析是高度非线性的。 下面就通过一个简单的案例带大家了解以下在ABAQUS中如何进行热辐射分析。1. 模型介绍 该案例模拟了一个直径为1m、高1m、初始温度20...

weixin_39670849的博客 1万+

oc-方法的参数传递一个对象

转载于:https://www.cnblogs.com/My-Cloud/p/4461455.html

and1111的博客 389

【已解决】飞牛nas(fnOS)异常断电导致硬盘未挂载(无法挂载),系统内部错误修复、救回数据全流程!(含更新系统后外接 NTFS 格式硬盘丢失的修复方法)

fnOS 飞牛NAS遭遇非正常断电后,存储空间显示「未挂载」或更新系统后外接 NTFS 格式硬盘丢失,点击挂载提示「系统内部错误」!💥 博主已经完美恢复,本文记录了相关的解决方案,帮您恢复或最大程度保住重要数据🎉

XiaoqiangClub的博客 2206

015:机载三维激光扫描技术相关知识

机载三维激光扫描系统(LiDAR)是集激光、GPS、INS等尖端技术于一体的三维航空遥感技术,能高效准确获取地表三维信息。该系统由GPS、INS、激光扫描测距系统、成像装置和工作平台组成,各部件协同工作以获取精确的空间定位、运动状态、地表三维坐标及真实色彩信息。通过制定飞行计划、安置GPS基站、激光扫描测量、惯性测量及获取高清数码影像等步骤,机载LiDAR技术能实时获取大范围高精度三维数据。该技术具有扫描速度快、精度高、全数字特征等优势,广泛应用于测绘、工程、环境监测和城市建设等领域,如城市三维模型重建、灾

qq_31762031的博客 1726

【Qt】窗体间传递数据(跨控件跨类),三种情况与处理方法

C++ Qt

shihoongbo的博客 2万+

vue3 - 高德地图定位出错Get ipLocation failed.Geolocation permission denied.(info: “FAILED“ | status: 0)报错解决!

vue3,nuxt3,高德地图,定位,位置,报错,AMap.Geolocation,解决报当前定位失败,高德地图H5 定位失败报错,web网页网站,报错详细解决教程,Get ipLocation failed.Geolocation permission denied.,高德地图定位报错info: "FAILED",高德地图status: 0,已经是https了还是报错,确保了浏览器位置已经开了,手机定位也开了,没解决,H5页面在ios的浏览器上使用 高德地图 报当前定位失败Geolocation,移动端设

✅ 精选推荐文章 6771

ios--OC调用JS传递参数并获得返回值(实例)

本例子是为了让大家能快速开发出OC调用JS功能的一个简单的例子。 1、准备一个本地化的html网页,如jsIOS.html js调用oc function postStr(str1,str2){ document.getElementB

程序员的良师益友 1万+

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

oc传参数给js_ios--网页js调用oc代码+传递参数+避免中文参数乱码的解决方案(实例)...

此解决方案为本人测试可行的方案,欢迎转载,如需转载,请注明出处,谢谢!此解决方案原理:1、在ViewController.h中声明方法和成员变量,以及webView的委托://// ViewController.h// JS_IOS_01//// Created by IMAC on 14-2-24.// Copyright (c) 2014年 Wanggsx. All rights re...

weixin_30895059的博客 150

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

oc调javascript方法(evaluateJavaScript:)&&js给oc发通知

在ios8中引入了WKWebView控件,通过在头文件引用 #import 来使用该控件, 这个控件与oc的原生控件uiwebview很相似,它更方便oc与js的相互通讯。 1。oc调用js方法例子: 通过方法: - (void)evaluateJavaScript:(NSString *)javaScriptString completionHandler:(v

ziyikongfu的专栏 2万+

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

OC控件的代理方法步骤

协议的使用步骤 1、声明协议 @class ItemView ; @protocol ItemViewDelegate @optional - (void)didItemView:(ItemView *)itemView atIndex:(NSInteger)index; @end @property (nonatomic, assign)

tooles的博客 623

Js与Oc交互总结

1.Oc调用Js方法  (1)JS调用OC-URL方法       示例1、准备一个本地化的html网页,如jsIOS.html html> head> meta http-equiv="content-type" content="text/html;charset=utf-8"> title>js调用octitle> sc

KaSuperMen的博客 522

通过WebViewJavascriptBridge实现OC与JS交互

这里照搬Github的Demo,其实还是很易懂的,首先,要在控制器的.h文件当中实现浏览器控件的协议: 1 #import <UIKit/UIKit.h> 2 3 @interface ExampleAppViewController : UINavigationController <UIWebViewDelegate> 4 5 @end ...

diangou2756的博客 158

如何给scrollview上添加的子控件UIView上添加手势

如果不做特殊处理,在scrollView上添加子控件UIView添加手势,如果是拖拽,轻扫手势,会发现,不起作用个,而是scrollView处理了事件,会产生scrollerview拖动事件,这不是我们需要的效果,如何处理呢,自定义一个继承至uiscrollview的控件, 设置两个属性,self.delaysContentTouches = NO; self.canCancelCo

lybeen2007的博客 2175

Swift Swift和OC混编

接触Swift有一段时间了,但是一直没有试过混合编程。难得的五一小长假,就有空简单的谢谢Swift和OC的混合编程的Demo。1.新建一个空的Swift项目 注意语言选择Swift。2.新建一个OC的控制器 注意语言选择OC。3.这一步很重要 一定要点击红框中的按钮。4.设置桥接文件路径 TARGETS–>Build Settings–>Objective-C Bridging Header

小猿猪哥的博客 5270

oc之mac中NSView的事件响应

mac开发系列17:定制NSView的事件处理 2017.08.14 11:39*字数 399阅读 217评论 0喜欢 1 这里以鼠标左击,即mouseDown为例。 我们通常的做法是,实现一个NSView的子类,例如mac微信中的MMView,然后在子类中重写mouseDown函数,再在mouseDown函数里面实现自己的事件处理逻辑。 不过,有些场景需要我们...

weixin_30593443的博客 1299

ios--网页js调用oc代码+传递参数+避免中文参数乱码的解决方案(实例)

此解决方案为本人测试可行的方案,欢迎转载,如需转载,请注明出处,谢谢! 此解决方案原理: 1、在ViewController.h中声明方法和成员变量,以及webView的委托: // // ViewController.h // JS_IOS_01 // // Created by IMAC on 14-2-24. // Copyright (c) 2014年 Wanggsx. Al

程序员的良师益友 4778

iOS 不规则形状选择 svg方案,原生方案。

公司项目要实现车辆部件选择的功能,由于各个部件形状不规则,所以原生控件很难满足需求。设计图类似下图:   点选车辆的部件要求变色,并记录点选状态以及其他一些属性的记录。   初始看到这个设计第一感觉是原生控件肯定不支持,需要自己画控件(shaplayer+path),但是再看看这些控件的形状,感觉全都自己画出来貌似不现实,很费劲。后来想到另一种方法,用原生的button,UI给切图,然后一...

Burt_Kingdom的博客 2670

UIScrollView与之子View的触摸事件

1、问题: 在一个UIScrollView上存在子View,该子View完全填充其父View(UIScrollView),此时,我需要一个触摸或者点击的事件,将子View移除,刚入坑IOS的我,绕了一大圈。 2、解决办法 刚开始,直接在子View上加上了三个UIGestureRecognizer,分别对应点击事件,上划和下划,测试的时候,点击事件的响应没有问题,但是上下划,全被父视图(UIS...

蜗牛想飞翔 683

iOS UIButton 传递参数的解决办法

需求 原生的UIButton的点击事件唯一的参数就是UIButton本身,我们通常使用UIButton自带的tag来使用不同的参数,在简单的业务场景下,通过tag都是可以满足需求的,但是在某些业务复杂的情况下,tag显得有些无力了,毕竟通过tag来传递点击事件传递参数只是一种间接的方式,没有将数据源关联到控件上。例如 table 视图有多个section,cell上有多个btn,那么btn的点击事...

LOLITA0164的博客 3万+
上一篇: UITextFiled 和UITextView 限定长度和判断输入表情
下一篇: 算法学习--合并排序
Coding_Physical
博客等级 码龄12年 160粉丝 210原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值