Skip to content

Commit

Permalink
补上Selector的内容
Browse files Browse the repository at this point in the history
  • Loading branch information
qinjx committed Mar 14, 2013
1 parent ce20603 commit 9ee88fd
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 19 deletions.
6 changes: 4 additions & 2 deletions how_does_mobile_device_get_location.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ GPS接收器与卫星2通信,获得与卫星2(记为Sat_2)的距离(记

分别以Sat_1, Sat_2为圆心,Dist_1, Dist_2为半径,画一个球,两球相交得一个空心圆,接收器在这个空心圆上某一点。

如果再有第三颗GPS卫星,同理画一个球,运气好的话,此球与空心圆有一个交点(相切),此时三颗星就可定位了。~~运气不好的话有两个交点,这就需要第四颗卫星来画第四个球了。~~ 如果不相切,球与圆圈有两个交点,排除一个不在地球表面的(可以理解为地球表面作为第四个球参与确定交点),剩下那个点即为接收机所在位置。
如果再有第三颗GPS卫星,同理画一个球,运气好的话,此球与空心圆有一个交点(相切),此时三颗星就可定位了。 如果不相切,球与圆圈有两个交点,排除一个不在地球表面的(可以理解为地球表面作为第四个球参与确定交点),剩下那个点即为接收机所在位置。

(注:之前,我想的是:运气不好的话三颗星只能画三个球面,有两个交点,这就需要第四颗卫星来画第四个球了。后来查了资料,才知道这不对,再加上地球本身第四个球面,已经可以唯一确定接收机的位置了)

### 仅依靠WIFI热点定位

wifi的有效距离比较有限,可以不考虑地球曲面的影响。把上面GPS定位原理的圆球改为圆圈,在水平面画圆圈。理论上,最好的情况下,两个wifi热点可定位成功(两个圆正好相切),三个wifi热点一定能找到唯一交点,定位成功。
wifi的有效距离比较有限,可以不考虑地球曲面的影响,简单认为wifi热点跟要定位的移动终端在同一个平面上。把上面GPS定位原理的圆球改为圆圈,在水平面画圆圈。理论上,最好的情况下,两个wifi热点可定位成功(两个圆正好相切),不在同一直线上的三个wifi热点一定能找到唯一交点,定位成功。

### 仅依靠GSM基站定位
与wifi定位相同
Expand Down
60 changes: 43 additions & 17 deletions ios.md
Original file line number Diff line number Diff line change
Expand Up @@ -336,29 +336,55 @@ selector就是一个方法指针,类似PHP里的动态方法名:
}

在Objective-C里,selector主要用来做两类事情:

##### 绑定控件触发的动作

@implementation DemoViewController
- (void)downButtonPressed:(id)sender{
UIButton *button = (UIButton*)sender ;
for (UIView *subView in [button.superview subviews]) {//遍历这个view的subViews
if ([subView isKindOfClass:NSClassFromString(@"UIButton")] )
{
UIButton *btn = (UIButton*) subView;
if (btn.selected) {
[btn setSelected:NO];
}
}
}
[button setSelected:YES];
- (void)downButtonPressed:(id)sender {//响应“按钮被按下事件”的方法
UIButton *button = (UIButton*)sender;
[button setSelected:YES];
}

- (void)drawAnButton() {
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
btn.frame = _frame;
btn.tag = 1;
btn.backgroundColor = [UIColor clearColor];
[btn addTarget: self action: @selector(downButtonPressed:) forControlEvents: UIControlEventTouchUpInside];//当这个按钮被按下时,触发downButtonPressed:方法
}
@end

#### 延时异步执行

@implementation ETHotDealViewController
- (void)viewDidLoad {
//获取数据源
HotDealDataSource *ds = [[HotDealDataSource alloc]init];
[ds reload];
_items = ds.items;
[super viewDidLoad];
staticHomeViewNav = self.navigationController;
//导航区设置
self.title = @"热点推荐";
[self.navigationController setNavigationBarHidden:NO animated:NO];
UIBarButtonItem* home = [ETAONavigationButtonFactory getHomeButtonWithTaget:self andAction:@selector(UIBarButtonHomeClick:)];
self.navigationItem.leftBarButtonItem = home;
[self performSelector:@selector(refreshTable) withObject:self afterDelay:0.5];//延迟0.5秒调用refreshTable方法
}

if (self._delegate && self._action && [self._delegate respondsToSelector:self._action]) {
[self._delegate performSelectorOnMainThread:self._action withObject:sender waitUntilDone:YES];
}
}
-(void)refreshTable
{
[self.tableView reloadData];
}
@end

这个例子中,获取数据源是通过ASIHTTP组件异步调用服务端HTTP接口,refreshTable要用到数据源返回回来的数据,如果不延迟0.5秒,就会立刻执行,执行的时候页面就是空白了(这时候数据还在路上呢)。

### 继承
### 协议(Protocol)
就是Java、PHP里的Interface
Expand Down

0 comments on commit 9ee88fd

Please sign in to comment.