无法识别的选择器通过创建工具栏按钮发送到实例

时间:2016-03-02 06:21:07

标签: ios objective-c uiwebview

我需要创建没有故事板的Web浏览器。我覆盖了init方法。看起来你的控制器类(按钮动作的目标)在按钮触发之前被释放。该按钮很可能由其超级视图保留。

-(id) init {

    self = [[super init] autorelease];

    myWV = [[UIWebView alloc] initWithFrame:self.view.bounds];
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
        [self loadPage];
    });

    UIToolbar *toolbar = [[UIToolbar alloc] init];
    toolbar.frame = CGRectMake(0, self.view.frame.size.height - 90 , self.view.frame.size.width, 44);
    NSMutableArray *items = [[NSMutableArray alloc] init];
    UIBarButtonItem *spacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:myWV action:nil];
    back = [[UIBarButtonItem alloc] initWithTitle:@"<" style:UIBarButtonItemStylePlain target:myWV action:@selector(goBack)];
    refresh = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:myWV action:@selector(reload)];
    stop = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemStop target:myWV action:@selector(stopLoading)];
    forward = [[UIBarButtonItem alloc] initWithTitle:@">" style:UIBarButtonItemStyleDone target:myWV action:@selector(goForward)];


    [items addObject:back];
    [items addObject:spacer];
    [items addObject:refresh];
    [items addObject:spacer];
    [items addObject:stop];
    [items addObject:spacer];
    [items addObject:forward];


    [toolbar setItems:items animated:NO];


    [items release];
    [self.view addSubview:toolbar];
    [toolbar release];

    return self;

}

错误文字:

2016-03-02 09:04:15.922 MerTask[12971:1157926] -[WebViewController addTopBarButton]: unrecognized selector sent to instance 0x7f9d72734e50
2016-03-02 09:04:15.963 MerTask[12971:1157926] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[WebViewController addTopBarButton]: unrecognized selector sent to instance 0x7f9d72734e50'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010f3a5e65 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x000000010ee1edeb objc_exception_throw + 48
    2   CoreFoundation                      0x000000010f3ae48d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
    3   CoreFoundation                      0x000000010f2fb90a ___forwarding___ + 970
    4   CoreFoundation                      0x000000010f2fb4b8 _CF_forwarding_prep_0 + 120
    5   MerTask                             0x000000010e03c129 -[WebViewController viewDidLoad] + 73
    6   UIKit                               0x000000010f8e8f98 -[UIViewController loadViewIfRequired] + 1198
    7   UIKit                               0x000000010f8e92e7 -[UIViewController view] + 27
    8   MerTask                             0x000000010e03b97a -[WebViewController init] + 138
    9   MerTask                             0x000000010e03c2eb -[MyTabBar init] + 139
    10  MerTask                             0x000000010e03b5e0 -[AppDelegate application:didFinishLaunchingWithOptions:] + 64
    11  UIKit                               0x000000010f7491f1 -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 272
    12  UIKit                               0x000000010f74a397 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 3415
    13  UIKit                               0x000000010f750cc6 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1760
    14  UIKit                               0x000000010f74de7b -[UIApplication workspaceDidEndTransaction:] + 188
    15  FrontBoardServices                  0x0000000112be3754 -[FBSSerialQueue _performNext] + 192
    16  FrontBoardServices                  0x0000000112be3ac2 -[FBSSerialQueue _performNextFromRunLoopSource] + 45
    17  CoreFoundation                      0x000000010f2d1a31 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    18  CoreFoundation                      0x000000010f2c795c __CFRunLoopDoSources0 + 556
    19  CoreFoundation                      0x000000010f2c6e13 __CFRunLoopRun + 867
    20  CoreFoundation                      0x000000010f2c6828 CFRunLoopRunSpecific + 488
    21  UIKit                               0x000000010f74d7cd -[UIApplication _run] + 402
    22  UIKit                               0x000000010f752610 UIApplicationMain + 171
    23  MerTask                             0x000000010e03b8d3 main + 99
    24  libdyld.dylib                       0x000000011199392d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

也许有人知道发生了什么事?

1 个答案:

答案 0 :(得分:0)

错误Picasso .with(context) .load(UsageExampleListViewAdapter.eatFoodyImages[1]) .memoryPolicy(MemoryPolicy.NO_CACHE, MemoryPolicy.NO_STORE) .into(imageViewFromDisk); - &gt;在[WebViewController addTopBarButton]:您已创建WebViewController,但尚未实施此方法。这样做。

addTopBarButton

-(void)addTopBarButton{

}

<强>选择-2

右键单击Storyboard中的-(IBAction)addTopBarButton:(Id)Sender{ } 按钮。将操作移至addTopBarButton