我只想在用户按下按钮时弹出通知。不需要服务器或计时器。我能找到的所有教程似乎都涉及这两者之一。
最佳答案
也许是这样的:
-(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];
}
它看起来像这样:
您还可以稍微自定义警报 View ,因此它可能具有用于文本输入的文本字段:
使用 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/