2011-07-07 45 views
0

在主视图中有一个navigationController上点击呼叫时的DetailView并在研讨会上添加一个按钮的UIBarButtonItem行上调用UIActionsheet

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]; 
} 

查看这个方法

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]; 
} 

,但我得到clicki错误NG上的按钮进行

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: 
+0

你会得到什么错误? – jamapag

+0

我将此添加到我的问题 –

+0

[myMenu showInView:self.view];这意味着你的自定义方法或任何? – maheswaran

回答

2

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)]; 
+0

谢谢!错误的目标,就是这样! –

0

它看起来像你实现在Seminar类的showMenu方法,但你说的吧按钮在SeminareListingView对象上调用它。如果是这种情况,那么您需要将bar按钮的代理设置为Seminar类的实例。

0

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