Mat*_*uyn -2 overriding subclass objective-c uilocalnotification
正在寻找一种方法来更改UILocalNotification的"关闭"按钮文本/功能......
我发现从另一个对象访问/调用text/function 是不可能的,尽管子类化 UILocalNotification应该允许实现方法覆盖 ...更不用说创建一个访问器来获取/设置"关闭"按钮文本字段.
你们怎么看待这件事?Apple会怎么样?
有人试过吗?......
编辑:12/21/2011 12:01 PM
我问的问题涉及对oop的理解:延迟/早期绑定,动态方法查找,以及声明的类型与运行时类型字段和方法处理.
UILocalNotification的子类化确实有效......
UILocalNotificationExampleSubclass * example = [UILocalNotificationExampleSubclass init];
... 然而,设备会创建一个对象,UILocalNotification
而不是类型UILocalNotificationExampleSubclass
.
我正在寻找对UILocalNotification.m文件方法的深入了解.
如果它没有自己的方法,那么什么对象(名称请)采用UILocalNotification的实例,使用它的字段,并显示我们在屏幕上看到的对象(名称)?
A UILocalNotification
只是通知信息的存储空间.它没有执行任何操作.
此外,您的应用程序不显示通知.另一个过程呢.所以子类化UILocalNotification
是没用的.
编辑于12月22日17:53 UTC + 1:
是的,你可以继承UILocalNotification
.但它UILocalNotification
是一个抽象类,它的所有属性都没有实现.alloc
重写该方法,以便返回UILocalNotification
私有子类的实例.这就是你无法实例化的原因UILocalNotificationExampleSubclass
.
但是,仍然没有指向子类,UILocalNotification
因为当您使用-[UIApplication scheduleLocalNotification:]
立即使用或显示通知时-[UIApplication presentLocalNotification:]
,操作系统会复制通知.
该副本存储在由系统管理的另一个进程中,该进程使用自己的私有存储机制.A UILocalNotification
只是一系列属性的存储,这些属性旨在被序列化并从应用程序发送到操作系统.
现在,我们有另一个进程存储所有已调度的本地通知并等待触发通知.当发生这种情况时,该过程将检查您的应用程序是否在前台.
UILocalNotification
类的属性外,我们无法以任何方式自定义该警报.UILocalNotification
.然后,UIApplication
共享实例将访问其delegate
属性并检查该委托是否实现application:didReceiveLocalNotification:
.如果是,您将收到通知,并可以使用该通知执行任何操作.例如,您可以选择使用警报视图显示通知.配置和显示警报视图可以这样完成:
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
UIAlertView *alertView =
[[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Alert", nil)
message:NSLocalizedString(notification.alertBody, nil)
delegate:nil
cancelButtonTitle:nil
otherButtonTitles:NSLocalizedString(@"OK", nil), nil];
[alertView show];
[alertView release]; // unless your project uses Automatic Reference Counting
}
Run Code Online (Sandbox Code Playgroud)
如果我所说的是真的,我希望这个更长的回答能回答你的问题.
归档时间: |
|
查看次数: |
1677 次 |
最近记录: |