我是 iOS 新手,正在研究Google Map SDK
并能够在视图上显示地图,但现在
- 我想添加一个
UITextField
并输入那里的位置 - 在按钮上单击该位置应显示在地图中
所以请帮助我。
我是 iOS 新手,正在研究Google Map SDK
并能够在视图上显示地图,但现在
UITextField
并输入那里的位置所以请帮助我。
我建议您在UINavigationBar上添加按钮,或者在地图视图的顶部放置一个UIToolBar,然后单击它显示一个带有文本字段的 UIAlertView,该文本字段接收输入,并在按下警报确定后获取输入的位置和做你的事。不要在地图上添加按钮,它会降低可用性因素。
如果你已经有导航栏,试试这个
UIBarButtonItem *locationButton = [[UIBarButtonItem alloc] initWithTitle:@"location" style:UIBarButtonItemStyleBordered target:self action:@selector(showAlertWithTextField)];
self.navigationItem.rightBarButtonItem=locationButton;
-(void)showAlertWithTextField{
UIAlertView* dialog = [[UIAlertView alloc] initWithTitle:@"Enter Location" message:@"" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Add", nil];
[dialog setAlertViewStyle:UIAlertViewStylePlainTextInput];
[dialog show];
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 1)
NSLog(@"%@",[[alertView textFieldAtIndex:0]text]);
}