UIBarButtonItem 调用 UIActionsheet
在主视图中,单击一行有一个导航控制器,调用详细视图并
添加一个按钮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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
坎吉
(Cange) 前往:
In
Cange to:
看起来您正在
Seminar
类中实现showMenu
方法,但您告诉栏按钮在SeminareListingView
上调用它目的。如果是这种情况,那么您需要将栏按钮的委托设置为Seminar
类的实例。It looks like you're implementing the
showMenu
method in theSeminar
class, but you're telling the bar button to call it on theSeminareListingView
object. If that's the case, then you need to set the bar button's delegate to an instance of theSeminar
class.你做错了。将您的 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.