如何调用栏按钮项目上的操作表
是的,但我有一个问题,我创建了一个继承自 uitableviewcontroller 的控制器,并且我编写了一个代码,该代码调用工具栏上的按钮项上的操作表,但它给了我一个错误。
mapType = [[[UIBarButtonItem alloc]initWithTitle:@"MAP TYPE" style:UIBarButtonItemStyleBordered target:self action:@selector(chooseMapType:)]autorelease];
self.toolbarItems = [NSArray arrayWithObjects:space, addButton, removeButton,mapType, nil]; [self.navigationController.view addSubview:self.navigationController.toolbar];
- (IBAction)chooseMapType:(id)sender {
UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"Map Type" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:kMapTypeRegular, kMapTypeSatellite, nil];
[sheet showFromToolbar:navigationController.toolbar];
[sheet release];
}
这是我已传递给选择器的方法。
- (void)actionSheet:(UIActionSheet*)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
NSString *clickedButtonTitle = [actionSheet buttonTitleAtIndex:buttonIndex];
if ([clickedButtonTitle isEqualToString:kMapTypeRegular])
[[self mapView] setMapType:MKMapTypeStandard];
else if ([clickedButtonTitle isEqualToString:kMapTypeSatellite])
[[self mapView] setMapType:MKMapTypeSatellite];
}
这是我的操作表方法,但它没有被调用,并给我一个错误 -[UIActionSheet _presentSheetFromView:above:], /SourceCache/UIKit_Sim/UIKit-1447.6.4/UIActionSheet。 – Abhishek 3 月 24 日 8:59
yes but i have a problem i have created a controller that inherits from uitableviewcontroller and i have written a code that calls action sheet on barbutton item on toolbar but it gives me an error.
mapType = [[[UIBarButtonItem alloc]initWithTitle:@"MAP TYPE" style:UIBarButtonItemStyleBordered target:self action:@selector(chooseMapType:)]autorelease];
self.toolbarItems = [NSArray arrayWithObjects:space, addButton, removeButton,mapType, nil]; [self.navigationController.view addSubview:self.navigationController.toolbar];
- (IBAction)chooseMapType:(id)sender {
UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"Map Type" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:kMapTypeRegular, kMapTypeSatellite, nil];
[sheet showFromToolbar:navigationController.toolbar];
[sheet release];
}
this is my method which i have passed to my selector .
- (void)actionSheet:(UIActionSheet*)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
NSString *clickedButtonTitle = [actionSheet buttonTitleAtIndex:buttonIndex];
if ([clickedButtonTitle isEqualToString:kMapTypeRegular])
[[self mapView] setMapType:MKMapTypeStandard];
else if ([clickedButtonTitle isEqualToString:kMapTypeSatellite])
[[self mapView] setMapType:MKMapTypeSatellite];
}
this i my action sheet method but it is not getting called and giving me an error that -[UIActionSheet _presentSheetFromView:above:], /SourceCache/UIKit_Sim/UIKit-1447.6.4/UIActionSheet. – Abhishek Mar 24 at 8:59
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请确保您的 chooseMapType 函数与 XIB 文件中的 UIBarButtonItem 正确连接。
Please ensure, your chooseMapType function is properly connected with UIBarButtonItem in your XIB file.