UIBarButtonItem 调用 UIActionsheet

发布于 2024-11-18 21:46:51 字数 2029 浏览 2 评论 0原文

在主视图中,单击一行有一个导航控制器,调用详细视图并

添加一个按钮SemimereListinView.m

#import "SeminareListingView.h"
#import "Seminar.h"


-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    //gehe zurück zum ersten View
    //NSLog(@"Received Data in seminareArray");

    Seminar *dvController = [[Seminar alloc] initWithNibName:@"Seminar" bundle:nil];

    NSString *selectedSeminarURL = [seminarURLArray objectAtIndex:indexPath.row];
    //NSString *selectedNextXMLFile = [kategorienNextXMLFileArray objectAtIndex:indexPath.row];

    dvController.seminarURLFromXML = selectedSeminarURL;
    //dvController.XMLFile = selectedNextXMLFile;

    [self.navigationController pushViewController:dvController animated:YES];


    //Zeige den PDF Download Button
    UIBarButtonItem *anotherButton = [[UIBarButtonItem alloc] initWithTitle:@"PDF Download" style:UIBarButtonItemStylePlain target:self action:@selector(showMenu)];

    //anotherButton.action = @selector(showMenu);

    dvController.navigationItem.rightBarButtonItem = anotherButton;

    [anotherButton release];

    [dvController release];
    dvController = nil;


    //[[self navigationController] popViewControllerAnimated:YES];
}

在研讨会视图中

有此方法Seminar.m

- (void) showMenu
{
    UIActionSheet *myMenu = [[UIActionSheet alloc]
                             initWithTitle: @"Überschrift"
                             delegate:self
                             cancelButtonTitle:@"Abbrechen"
                             destructiveButtonTitle:@"Etwas unwiderrufliches"
                             otherButtonTitles:@"Eins", @"Zwei", nil];
    [myMenu showInView:self.view];
}

但我通过单击按钮收到错误

2011-07-07 12:57:31.009 Seminar App2[4352:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[SeminareListingView showMenu]: unrecognized selector sent to instance 0x6305f90'
*** Call stack at first throw:

in main view a have an navigationController on click on a row a call the detailview and add a button

seminareListinView.m

#import "SeminareListingView.h"
#import "Seminar.h"


-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    //gehe zurück zum ersten View
    //NSLog(@"Received Data in seminareArray");

    Seminar *dvController = [[Seminar alloc] initWithNibName:@"Seminar" bundle:nil];

    NSString *selectedSeminarURL = [seminarURLArray objectAtIndex:indexPath.row];
    //NSString *selectedNextXMLFile = [kategorienNextXMLFileArray objectAtIndex:indexPath.row];

    dvController.seminarURLFromXML = selectedSeminarURL;
    //dvController.XMLFile = selectedNextXMLFile;

    [self.navigationController pushViewController:dvController animated:YES];


    //Zeige den PDF Download Button
    UIBarButtonItem *anotherButton = [[UIBarButtonItem alloc] initWithTitle:@"PDF Download" style:UIBarButtonItemStylePlain target:self action:@selector(showMenu)];

    //anotherButton.action = @selector(showMenu);

    dvController.navigationItem.rightBarButtonItem = anotherButton;

    [anotherButton release];

    [dvController release];
    dvController = nil;


    //[[self navigationController] popViewControllerAnimated:YES];
}

in the seminar view a have this method

seminar.m

- (void) showMenu
{
    UIActionSheet *myMenu = [[UIActionSheet alloc]
                             initWithTitle: @"Überschrift"
                             delegate:self
                             cancelButtonTitle:@"Abbrechen"
                             destructiveButtonTitle:@"Etwas unwiderrufliches"
                             otherButtonTitles:@"Eins", @"Zwei", nil];
    [myMenu showInView:self.view];
}

but i get an error by clicking on Button

2011-07-07 12:57:31.009 Seminar App2[4352:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[SeminareListingView showMenu]: unrecognized selector sent to instance 0x6305f90'
*** Call stack at first throw:

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

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

发布评论

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

评论(3

寄与心 2024-11-25 21:46:51

坎吉

UIBarButtonItem *anotherButton = [[UIBarButtonItem alloc] initWithTitle:@"PDF Download" style:UIBarButtonItemStylePlain target:self action:@selector(showMenu)];

(Cange) 前往:

UIBarButtonItem *anotherButton = [[UIBarButtonItem alloc] initWithTitle:@"PDF Download" style:UIBarButtonItemStylePlain target:dvController action:@selector(showMenu)];

In

UIBarButtonItem *anotherButton = [[UIBarButtonItem alloc] initWithTitle:@"PDF Download" style:UIBarButtonItemStylePlain target:self action:@selector(showMenu)];

Cange to:

UIBarButtonItem *anotherButton = [[UIBarButtonItem alloc] initWithTitle:@"PDF Download" style:UIBarButtonItemStylePlain target:dvController action:@selector(showMenu)];
林空鹿饮溪 2024-11-25 21:46:51

看起来您正在 Seminar 类中实现 showMenu 方法,但您告诉栏按钮在 SeminareListingView 上调用它目的。如果是这种情况,那么您需要将栏按钮的委托设置为 Seminar 类的实例。

It looks like you're implementing the showMenu method in the Seminar class, but you're telling the bar button to call it on the SeminareListingView object. If that's the case, then you need to set the bar button's delegate to an instance of the Seminar class.

面如桃花 2024-11-25 21:46:51

你做错了。将您的 barButton ite 代码放入研讨会的 viewDidLoad 中。您正在添加目标 self,它表示堆栈的当前视图,而您实际上想要将目标分配给研讨会控制器。因此,请剪切从 cellForRowMethod 到研讨会控制器的 viewDidLoad 的代码(添加 BarButtonItem)。

you are doing it wrong. Put your barButton ite code into viewDidLoad of Seminar. You are adding target self which denotes to current view of stack while you actually want to assign target to Seminar Controller. So please cut the code(Adding BarButtonItem) from cellForRowMethod to viewDidLoad of Seminar Controller.

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