selector

Are selectors in Objective-C just another way to send a message to an object?

大兔子大兔子 提交于 2019-12-17 18:11:08
问题 Are selectors in Objective-C just another way to send a message to an object? I really don't understand why or how to use them. 回答1: They aren’t another way to send a message to an object, they’re the only way. For example, in [myView setValue:@"foo"] , setValue: is a selector. (Another, less convenient way of writing the same thing is objc_msgSend(myView, @selector(setValue:), @"foo") .) As Ian Henry says, you can use SEL values to choose a selector at runtime instead of compile time. This

Understanding Swift 2.2 Selector Syntax - #selector()

巧了我就是萌 提交于 2019-12-17 17:39:22
问题 I am switching over the syntax of my project toward Swift 2.2 (which xCode helps me do automatically); however, I do not understand the new #selector() syntax. As an example: timer = NSTimer.scheduledTimerWithTimeInterval(1.0, target: self, selector: #selector(MyVC.timerCalled(_:)), //new selector syntax! userInfo: nil, repeats: true) This has the selector #selector(MyVC.timerCalled(_:)) What does the _: signify? Can you add other variables into this selector? Say, #MyVC.timerCalled(_

[高并发Java 八] NIO和AIO

不问归期 提交于 2019-12-17 16:17:20
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> IO感觉上和多线程并没有多大关系,但是NIO改变了线程在应用层面使用的方式,也解决了一些实际的困难。而AIO是异步IO和前面的系列也有点关系。在此,为了学习和记录,也写一篇文章来介绍NIO和AIO。 1. 什么是NIO NIO是New I/O的简称,与旧式的基于流的I/O方法相对,从名字看,它表示新的一套Java I/O标 准。它是在Java 1.4中被纳入到JDK中的,并具有以下特性: NIO是基于块(Block)的,它以块为基本单位处理数据 (硬盘上存储的单位也是按Block来存储,这样性能上比基于流的方式要好一些) 为所有的原始类型提供(Buffer)缓存支持 增加通道(Channel)对象,作为新的原始 I/O 抽象 支持锁(我们在平时使用时经常能看到会出现一些.lock的文件,这说明有线程正在使用这把锁,当线程释放锁时,会把这个文件删除掉,这样其他线程才能继续拿到这把锁)和内存映射文件的文件访问接口 提供了基于Selector的异步网络I/O 所有的从通道中的读写操作,都要经过Buffer,而通道就是io的抽象,通道的另一端就是操纵的文件。 2. Buffer Java中Buffer的实现。基本的数据类型都有它对应的Buffer Buffer的简单使用例子: package test; import

Customizing tabs on state in Android

ぐ巨炮叔叔 提交于 2019-12-17 15:37:27
问题 I know how to put the icon on each tab, that is no problem. I also ran across this : [Stack Overflow thread on pretty much same thing][1] I followed one of the links from that question and found [this][2] Pretty much, it said to use a selector defined in the XML, sure, did that. But there is no id associated w/ it so I am not sure how to get the selector function as a drawable so I can use it as the icon for the tabs. Maybe I am going about this the wrong way. But this is what I have, and

Android: textColor of disabled button in selector not showing?

你。 提交于 2019-12-17 15:13:13
问题 I am trying to make a button with a selector my button can have the following states: Enabled/Disabled Pressed/Not Pressed According to the states mentioned above. I need to manipulate the button's: Text color background image The button starts off my being disabled so it should have the disabled textColor and the disabled button background. But I can see the default textColor (specified in style) and NO background image! Here is my selector button_selector.xml <?xml version="1.0" encoding=

When to use a colon with a @selector

对着背影说爱祢 提交于 2019-12-17 10:52:21
问题 Just getting going with iPhone development and Objective-C . Yesterday I was trying to addObserver for a notification in a view of mine, and I kept getting this error: unrecognized selector sent to instance I tracked it down to the fact that I needed to include the trailing colon to my selector argument: [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(nameOfMySelector:) name:@"BBLocationServicesAreDisabled" object:nil]; Today, I thought I was clever because when

Passing parameters to the method called by a NSTimer

风格不统一 提交于 2019-12-17 10:18:39
问题 How can I pass a parameter to the method called by a NSTimer? My timer looks like this: [NSTimer scheduledTimerWithTimeInterval:4 target:self selector:@selector(updateBusLocation) userInfo:nil repeats:YES]; and I want to be able to pass a string to the method updateBusLocation. Also, where am supposed to define the method updateBusLocation? In the same .m file that I create the timer? EDIT: Actually I am still having problems. I am getting the error message: Terminating app due to uncaught

Passing parameters on button action:@selector

久未见 提交于 2019-12-17 05:01:54
问题 I want to pass the movie url from my dynamically generated button to MediaPlayer: [button addTarget:self action:@selector(buttonPressed:) withObject:[speakers_mp4 objectAtIndex:[indexPath row]] forControlEvents:UIControlEventTouchUpInside]; but action:@selector() withObject: does not work? Is there any other solution? Thanks for help! 回答1: Edit. Found a neater way! One argument that the button can receive is (id)sender . This means you can create a new button, inheriting from UIButton, that

List selectors for Objective-C object

送分小仙女□ 提交于 2019-12-17 04:21:28
问题 I have an object, and I want to list all the selectors to which it responds. It feels like this should be perfectly possible, but I'm having trouble finding the APIs. 回答1: This is a solution based on the runtime C functions: class_copyMethodList returns a list of class methods given a Class object obtainable from an object. #import <objc/runtime.h> [..] SomeClass * t = [[SomeClass alloc] init]; int i=0; unsigned int mc = 0; Method * mlist = class_copyMethodList(object_getClass(t), &mc); NSLog

What is the Swift equivalent of respondsToSelector?

梦想的初衷 提交于 2019-12-16 23:37:15
问题 I've googled but not been able to find out what the swift equivalent to respondsToSelector: is. This is the only thing I could find (Swift alternative to respondsToSelector:) but isn't too relevant in my case as its checking the existence of the delegate, I don't have a delegate I just want to check if a new API exists or not when running on the device and if not fall back to a previous version of the api. 回答1: As mentioned, in Swift most of the time you can achieve what you need with the ?