objective-c - 如何向 iOS 用户发送即时本地通知?

标签 objective-c ios xcode cocoa-touch

我只想在用户按下按钮时弹出通知。不需要服务器或计时器。我能找到的所有教程似乎都涉及这两者之一。

最佳答案

也许是这样的:

-(IBAction) buttonPressed: (UIButton *)sender{

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle: [NSString stringWithFormat:@"You pressed button %@", sender.tag]  
                                                    message: @"message" 
                                                   delegate: self 
                                          cancelButtonTitle: @"Ok" 
                                          otherButtonTitles: nil]];
    [alert show];
}

它看起来像这样:

enter image description here

您还可以稍微自定义警报 View ,因此它可能具有用于文本输入的文本字段:

enter image description here

使用 UIAlertViews,您还可以实现协议(protocol)方法,如 – alertView:clickedButtonAtIndex:– alertView:willDismissWithButtonIndex:根据他们按下的警报按钮执行不同的操作。

这是一个关于 UIAlertViews 和实现它们的协议(protocol)方法的好教程:http://mobile.tutsplus.com/tutorials/iphone/uialertview/ .

如果您不想使用 UIAlertViews 而想要更可定制的模态视图,请查看这两个名为 UAModalPanel 的优秀库。和 MJPopupViewController .您可以查看有关这两个库的图像、演示和更多信息的链接,包括指向它们的 github 页面的链接,您可以在其中下载它们。

希望这可以帮助!

关于objective-c - 如何向 iOS 用户发送即时本地通知?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11533798/

相关文章:

ios - UIImageView 不会调整大小以匹配 UIView 的框架

objective-c - 如何设计一个应用程序来在 iOS 中跨模型保留一组字符串?

ios - 在没有管理员帐户的情况下推送到 TestFlight?

objective-c - NSLog,如何为不同大小的字段生成固定宽度的输出?

ios - 如何在 IOS 中隐藏 UILabel 中的文本

ios - 如何将 MKMapView 的单例类设置为 Storyboard 中的 map ?

objective-c - Cocoa/Objc - 日期格式更改

ios - 使标签只达到需要的宽度?

ios - Xcode 7.0.1 with CocoaPods 应用程序编译错误退出代码 1

objective-c - 清除/删除 Xcode 项目中的所有连接