开发者

Objective C implementation of controlTextDidChange: in .h and .m files

开发者 https://www.devze.com 2023-01-05 11:45 出处:网络
Can开发者_运维问答 someone post the simplest example on how to use controlTextDidChange with a text label in the .h and .m files? Another part of my code constantly changes the value of this text labe

Can开发者_运维问答 someone post the simplest example on how to use controlTextDidChange with a text label in the .h and .m files? Another part of my code constantly changes the value of this text label multiple times a second. I just need another part of my script that can tell if the value has changed and preform an action. All these websites out there that have this topic don't cover how to FULLY use it. So I thought I would ask it here! :D

Thanks! Elijah


It sounds like you're taking a pretty inappropriate approach to your problem. Specifically, you're using a control to store data, rather than storing it separately in your model and interacting with that model from the rest of your application.

I think you need to take a step back and do the following:

  1. Learn the principles of object-oriented programming and the Model-View-Controller pattern, particularly as they apply to Cocoa. One of the best introductions is the book Object-Oriented Programming with Objective-C, online free from Apple.

  2. Plan out a bit of the structure behind your application - how the data it works with fits together, not just how the user interface will look. Your application's user interface and the data it works with are related but not the same.

That will probably help you get the "big picture" for your application right, and show you more easily how to put together the pieces like "do X when this value changes" and "put the value for that in a text field" than trying to learn only the pieces you think you need as you think you need them.

One more thing: Your application is an application, not a script as you referred to it in your question. This is important to keep in mind: An application can have quite a few moving parts. Tools like separate classes, separate .h and .m files, and so on are ways of managing these parts and keeping them as independent from each other as appropriate.

It's also not just a sequence of "commands" that are executed one after the other as a script might be. Instead, the interactions between the parts of an application are managed by the Cocoa framework, according to its application lifecycle. The Application Architecture Overview and the Cocoa Fundamentals Guide are good to read in order to get a grounding in how Cocoa fits together with your own code when building applications.

0

精彩评论

暂无评论...
验证码 换一张
取 消