Invalid ovelroad

Trying to work out the correct syntax but getting “Invalid Overload”

method DetailView.DoclickClose;
begin
  (parentViewController as UINavigationController).popViewControllerAnimated(true);
end;

method DetailView.init: instancetype;
var
  ACloseButton: UIBarButtonItem;
begin
  inherited;
  title := 'My Detail View'  
  ACloseButton := new UIBarButtonItem withTitle('Close') style(UIBarButtonItemStyle.Plain) target(nil) action(DoclickClose);
end;

Anyone help with this?

On which call? i’ll have a look once i’m back at the computer later today.

FTR, i ghee the following error messages:

ACloseButton := new UIBarButtonItem withTitle('Close') style(UIBarButtonItemStyle.Plain) target(nil) action(DoclickClose); 
// H3 parameter 4 is "Void" should be "SEL"
// E407 No overloaded constructor with these parameters for type "UIBarButtonItem", best matching overload is "constructor withTitle(title: NSString) style(style: UIBarButtonItemStyle) target(target: id) action(action: SEL): instancetype"

with the H3 hint indicating what the exact problem is. you will want to pass selector(DoclickClose), because the way you write it you are calling DoclickClose and passing the result (which the method doesn’t have ;), but a selector (type SEL) is expected instead.

Full call:

ACloseButton := new UIBarButtonItem withTitle('Close') style(UIBarButtonItemStyle.Plain) target(nil) action(selector(DoclickClose));

Unrelated tip, instead of method DetailView.init: instancetype;, just use Co structure syntax:

constructor DetailView;
begin
  ...
end;

both work, but the latter is so much nicer (and cross-platform).

Thanks Marc!

Still learning but from what I’ve seen so far this is fucking awesome!

Great work!

1 Like

I haven’t tested yet but I think my mistake was just looking at the inline error message. I’m guessing more information is given in the build log… I’ll make sure I check this in future.

Looking forward to getting back to this.

1 Like

cool! can i use that quote on the website? :wink:

Options-Cmd-Left/RIght lets you toggle between the different messages on a line, if there’s more than one. I’ll look at options for improving how they show.

Absolutely! Feel free to use anything I say :wink:

1 Like