IM 即时通讯 (438)
Android (207)
- 初始化&链接 (8)
- 事件&监听处理 (7)
- 用户信息 (13)
- 会话列表 (15)
- 聊天会话 (26)
- 消息处理 (35)
- 自定义消息 (6)
- 音视频 (2)
- 推送&通知 (33)
- 扩展功能 (4)
- 第三方地图 (3)
- 依赖&配置 (9)
- 升级说明 (3)
- 其他 (43)
iOS (166)
- SDK 导入 (9)
- 连接 (8)
- 事件处理 (2)
- 用户信息 (3)
- 会话列表 (14)
- 聊天会话 (44)
- 消息处理 (25)
- 自定义消息 (8)
- 推送&通知 (19)
- 扩展功能 (5)
- 国际化 (3)
- 音视频 (3)
- 其他 (23)
Web (36)
Server (29)
继承位置页面 RCLocationPickerViewController,实现发送位置到聊天界面。
在继承位置页面 RCLocationPickerViewController 后,实现导航栏左右按钮功能,即发送位置消息到聊天界面。
发布时间: 2016-04-06 10:31
回答:
1.创建 RCLocationPickerViewController 的子类:RCDLocationViewController,可以实现自定义导航栏左右按钮,代码如下:
- (void)viewDidLoad { [super viewDidLoad]; self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"自定义左按钮" style:UIBarButtonItemStyleDone target:self action:@selector(leftItemDidPressed:)]; self.navigationItem.leftBarButtonItem.tintColor = [UIColor redColor]; self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"自定义右按钮" style:UIBarButtonItemStyleDone target:self action:@selector(rightItemDidPressed:)]; self.navigationController.navigationBar.barTintColor = [UIColor blueColor]; } - (void)leftItemDidPressed:(id)sendr { [self dismissViewControllerAnimated:YES completion:nil]; } - (void)rightItemDidPressed:(id)sendr { [super rightBarButtonItemPressed:nil]; }
2.在聊天页子类重写以下下方法,并设置代理,present 到子类的对象中。
- (void)pluginBoardView:(RCPluginBoardView *)pluginBoardView clickedItemWithTag:(NSInteger)tag { switch (tag) { case PLUGIN_BOARD_ITEM_LOCATION_TAG: { RCDLocationViewController *vc = [[RCDLocationViewController alloc] init]; vc.delegate = self; UINavigationController *navi = [[UINavigationController alloc] initWithRootViewController:vc]; [self presentViewController:navi animated:YES completion:nil]; } break; default: [super pluginBoardView:pluginBoardView clickedItemWithTag:tag]; break; } }
3.聊天页子类需要遵循代理 RCLocationPickerViewControllerDelegate,并实现方法:
- (void)locationPicker:(RCLocationPickerViewController *)locationPicker didSelectLocation:(CLLocationCoordinate2D)location locationName:(NSString *)locationName mapScreenShot:(UIImage *)mapScreenShot { RCLocationMessage *locationMessage = [RCLocationMessage messageWithLocationImage:mapScreenShot location:location locationName:locationName]; [self sendMessage:locationMessage pushContent:nil]; }