iphone - 如何以编程方式为 UIWebView 创建后退、前进和刷新按钮?

标签 iphone xcode uiwebview

我当前创建了一个 webview,但我不想使用界面生成器来创建后退、前进和刷新按钮。我如何以编程方式创建这些按钮?我知道如何用代码创建常规按钮,但对于 webView 委托(delegate)按钮,我迷失了方向,无法找到很多资源。

最佳答案

来自 UIWebView 文档:

If you allow the user to move back and forward through the webpage history, then you can use the goBack and goForward methods as actions for buttons. Use the canGoBack and canGoForward properties to disable the buttons when the user can’t move in a direction.

然后设置按钮将使用 addTarget:action:forControlEvents: (如 Sven 所指出的):

[myBackButton addTarget:myWebView
                 action:@selector(goBack)
       forControlEvents:UIControlEventTouchDown];

如果您想根据 canGoBackcanGoForward 属性启用/禁用按钮,则必须向 添加一些 KVO 通知UIController.

关于iphone - 如何以编程方式为 UIWebView 创建后退、前进和刷新按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3639411/

相关文章:

javascript - uiwebview javascript 没有返回

c# - QLPreviewController 和 UIWebView 不显示填充的 PDF

iOS Quickblox 聊天 : getting error: Code=-999 "You need to enable stream management to use this feature

ios - 没有 UIViewAnimationOptionBeginFromCurrentState,UIView 动画无法工作

iphone - 离开 View 后保留/保留变量

iphone - 自定义、无图像的 UIButton 标题消失

xcode - 快速在页脚表格 View 中添加按钮

ios - 保留 "session only"cookies, iOS

ios - UICollectionViewCell 消息在出队后立即发送到已释放的实例

iphone - 在iPhone SDK上绘制类似于矩阵结构的点