为 Web 视图添加 UI 栏按钮项,但应用崩溃

Adding UI Bar Button Items for WebView but app crashing

本文关键字:应用 崩溃 按钮 Web 视图 添加 UI      更新时间:2023-10-16

我已经在XCode中将以下代码添加到我的iOS项目中。它允许我向我的UINavigation控制器添加多个按钮 - 这些项目在应用程序中显示正常,但是当我按下"刷新"或"返回"按钮时,应用程序崩溃

我要做的是创建3个按钮 - 刷新,返回和前进。

我收到的错误说未声明的选择器"刷新"

// Create the refresh, fixed-space (optional), and profile buttons.
UIBarButtonItem *refreshBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(refresh:)];


//    // Optional: if you want to add space between the refresh & profile buttons
//    UIBarButtonItem *fixedSpaceBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
//    fixedSpaceBarButtonItem.width = 12;
UIBarButtonItem *profileBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:self action:@selector(goToProfile)];
profileBarButtonItem.style = UIBarButtonItemStyleBordered;
self.navigationItem.rightBarButtonItems = @[profileBarButtonItem, /* fixedSpaceBarButtonItem, */ refreshBarButtonItem];

请点击链接

将在导航栏中添加更多按钮

检查refresh方法的声明/定义。

根据您的代码action:@selector(refresh:); refresh方法应至少有一个参数。

如果你对refresh方法的定义没有参数,那么它应该像action:@selector(refresh);