工具栏上的按钮应调用位置管理器方法
我是 iPhone 开发新手。我创建了一个地图应用程序。我在地图视图下方创建了一个工具栏。当我单击工具栏上的按钮时,它应该显示一个警报视图,要求设置当前位置。我怎样才能实现它。请指导我。我应该在哪里给出按钮单击事件的方法。我已经在界面生成器中创建了工具栏。请帮助我。谢谢。
I am new to iphone development.I have created a map application.I have created a tool bar below the mapview.When i click the button on the tool bar it should display an alert view asking to set the current location .How can i achieve it.please guide me .Where should i give method for the button click event.I have created the toolbar in interface builder.Please help me out.Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该方法应该进入与 XIB(发音为 NIB)文件关联的控制器中。在该控制器的标头中,您将声明一个方法,例如
-(IBAction) userPressedButton:(id) sender;
保存 .h,然后返回 InterfaceBuilder,选择按钮并按 cmd-2 显示插座检查器。将“Touch Up Inside”拖至图标计数窗口中的“文件所有者”。该 FileOwner 对象是您的控制器。当您放开时,它将弹出控制器中所有操作的菜单,因此您应该看到 userPressedButton 方法。单击该按钮。
然后在实现 (.m) 文件中,您可以实现该方法来执行您想要的任何操作,例如显示 AlertView 等。基本上,XIB 的文件所有者是控制器类,并且您刚刚告诉 IB,当手指被在按钮区域内抬起,它应该调用 userPressedButton 方法。
简单 ;-) 开始时很奇怪,然后就很棒了。
The method should go in the controller associated with XIB (pronounced NIB) file. In the header of that controller you will declare a method such as
-(IBAction) userPressedButton:(id) sender;
Save the .h, and return to InterfaceBuilder, select your button and press cmd-2 to show the inspector for outlets. Drag "Touch Up Inside" to File Owner in the window countaining the icons. That FileOwner object is your controller. When you let go it will pop-up a menu of all of the Actions in the controller, so you should see your userPressedButton method. Click that.
Then in the implementation (.m) file you, well, implement that method to do whatever you want such as display an AlertView etc. Basically the XIB's file owner is the controller class, and you've just told IB that when a finger is lifted up inside the area of your button, it should call the userPressedButton method.
Simples ;-) It's strange to start with, then wonderful.