可以子类化 UILocalNotification 并更改默认“关闭”按钮文本和方法?
正在寻找一种方法来更改UILocalNotification的“关闭”按钮文本/功能...
我发现它不可能访问/从另一个对象调用文本/函数,尽管子类化 UILocalNotification 应该允许实现方法覆盖...更不用说创建访问器获取/设置“关闭”按钮文本字段。
大家对此有何看法? 苹果会怎么做?
有人尝试过吗?...
编辑:12/21/2011 12:01 PM
我问的问题涉及对 oop: Late 的理解/早期绑定、动态方法查找以及声明类型与运行时类型字段和方法处理。
UILocalNotification 的子类化确实工作...
UILocalNotificationExampleSubclass * example = [UILocalNotificationExampleSubclass init];
...并且设备确实创建一个对象,但是,类型为 UILocalNotification
而不是 UILocalNotificationExampleSubclass
。
我正在寻找对 UILocalNotification.m 文件方法的深入了解。
如果它没有有自己的方法,那么什么对象(请提供名称)采用 UILocalNotification 的实例,使用其字段,并显示该对象(请提供名称) )我们在屏幕上看到了什么?
Searching for a way to change the "Close" button text/functionality of a UILocalNotification...
I've found that it's impossible to access/call the text/function from another object, although subclassing UILocalNotification should allow implementation method overrides... not to mention the creation of an accessor to get/set the "Close" button text field.
What do you guys think about this? What would Apple?
Has anyone tried?...
EDIT: 12/21/2011 12:01 PM
The question that I'm asking involves an understanding of oop: late/early binding, dynamic method lookup, and declared type vs. runtime type field and method handling.
Subclassing of UILocalNotification does work...
UILocalNotificationExampleSubclass * example = [UILocalNotificationExampleSubclass init];
...and the device does create an object, however, with type UILocalNotification
and not UILocalNotificationExampleSubclass
.
I'm looking for insight into the UILocalNotification.m file's methods.
If it does not have its own methods, what object (name please) takes an instance of a UILocalNotification, uses its fields, and displays the object (name please) we see on screen?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
UILocalNotification
只是通知信息的存储。它不执行任何操作。此外,您的应用程序不会显示通知。另一个进程也可以。所以子类化
UILocalNotification
是没有用的。编辑,12 月 22 日 17:53 UTC+1:
是的,您可以对
UILocalNotification
进行子类化。但是 UILocalNotification 是一个抽象类,它的任何属性都没有实现。alloc
方法被重写,因此它返回一个私有子类UILocalNotification
的实例。这就是为什么您无法实例化UILocalNotificationExampleSubclass
。但仍然没有指向子类
UILocalNotification
因为当您使用-[UIApplication ScheduleLocalNotification:]
或使用-[UIApplication PresentLocalNotification:]
,操作系统复制通知。该副本存储在系统管理的另一个进程中,该进程使用自己的私有存储机制。 UILocalNotification 只是一组属性的存储,这些属性注定要被序列化并从应用程序发送到操作系统。
现在,我们有另一个进程存储所有计划的本地通知并等待通知触发。发生这种情况时,该进程将检查您的应用程序是否位于前台。
UILocalNotification
新实例的应用程序。然后,UIApplication
共享实例将访问其delegate
属性并检查该委托是否实现应用程序:didReceiveLocalNotification:
。如果是这样,您会收到通知,并可以使用该通知执行您想要的任何操作。例如,您可以选择使用警报视图显示通知。配置和显示警报视图可以这样完成:
我希望这个较长的响应能够回答您的问题,如果我说的是真的。
A
UILocalNotification
is just a storage for the notification's information. It does not perform anything.Moreover your application does not display the notification. Another process does. So subclassing
UILocalNotification
is just useless.EDIT at December 22nd, 17:53 UTC+1:
Yes, you can subclass
UILocalNotification
. ButUILocalNotification
is an abstract class and none of its properties is implemented. Thealloc
method is overridden so it returns an instance ofUILocalNotification
, a private subclass. That's why you cannot instantiateUILocalNotificationExampleSubclass
.But still, there is not point to subclass
UILocalNotification
because when you schedule a notification using-[UIApplication scheduleLocalNotification:]
or present the notification immediately using-[UIApplication presentLocalNotification:]
, the operating system copies the notification.That copy is stored in another process managed by the system, which uses its own private storage mechanism. A
UILocalNotification
is just a storage for a bunch of properties that is destined to get serialized and sent from the application to the operating system.Now, we have that other process storing all the scheduled local notifications and waiting for a notification to fire. When that happens, that process will check if your application is in the foreground.
UILocalNotification
class.UILocalNotification
. Then, theUIApplication
shared instance will access itsdelegate
property and check if that delegate implementsapplication:didReceiveLocalNotification:
. If it does, you get the notification back and can do anything you want with that notification. For example, you may choose to display the notification using an alert view.Configuring and displaying the alert view can be done like this:
I hope this longer response did answer your question, if what I'm saying is true.