UIBarButtonItem call UIActionsheet
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: '-[SeminareListingVi开发者_开发百科ew showMenu]: unrecognized selector sent to instance 0x6305f90'
*** Call stack at first throw:
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)];
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.
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.
精彩评论