具有多个参数的方法的选择器

发布于 2024-10-02 16:17:34 字数 470 浏览 0 评论 0原文

大家好,我需要为此方法编写选择器。我该怎么做呢?谢谢!

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 

这是我需要的代码:

UIBarButtonItem *deleteButton = [[UIBarButtonItem alloc]  initWithTitle:@"Delete User" style:UIBarButtonItemStyleBordered target:self action:@selector(my_button_click_here_is_need_a_selector:)];

[toolbar setItems:[NSArray arrayWithObjects: deleteButton, nil]];

Hi all I need to write selector for this method. How can I do it? Thanx!

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 

Here is the code where I need it:

UIBarButtonItem *deleteButton = [[UIBarButtonItem alloc]  initWithTitle:@"Delete User" style:UIBarButtonItemStyleBordered target:self action:@selector(my_button_click_here_is_need_a_selector:)];

[toolbar setItems:[NSArray arrayWithObjects: deleteButton, nil]];

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

放低过去 2024-10-09 16:17:34

请参阅如何将方法参数传递给选择器了解如何为该方法创建一个选择器(答案是@selector(tableView:cellForRowAtIndexPath:))。

但是,如果您传递此选择器,则您将错误地使用 -initWithTitle:... 方法。 action 的选择器必须是其中一种形式的回调,

-(IBAction)clicked;
-(IBAction)clicked:(id)sender;
-(IBAction)clicked:(id)sender withEvent:(UIEvent*)event;

-tableView:cellForRowAtIndexPath: 不是以上任何一种形式。您应该为其编写一个特定的方法。

See How to pass method arguments to a selector on how to create a selector for that method (the answer is @selector(tableView:cellForRowAtIndexPath:)).

But you are using the -initWithTitle:… method wrongly if you pass this selector. The action's selector must be a callback in the one of the forms

-(IBAction)clicked;
-(IBAction)clicked:(id)sender;
-(IBAction)clicked:(id)sender withEvent:(UIEvent*)event;

the -tableView:cellForRowAtIndexPath: is none of the above. You should write a specific method for it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文