- 发送短信验证码60s倒计时
在发送验证码按钮的点击事件方法里的实现代码
__block NSUInteger count = 60;
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_source_t _timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue);
dispatch_source_set_timer(_timer, dispatch_walltime(NULL, 0), 1.0 * NSEC_PER_SEC, 0);//每秒执行
dispatch_source_set_event_handler(_timer, ^{
if (count <= 0) {//倒计时结束 关闭
dispatch_source_cancel(_timer);
dispatch_async(dispatch_get_main_queue(), ^{
//设置验证码按钮
[self.messageButton setTitle:@"请求验证码" forState:(UIControlStateNormal)];
self.messageButton.userInteractionEnabled = YES;
});
}else {
int seconds = count % 60;
NSString *strTime = [NSString stringWithFormat:@"%.2d",seconds];
dispatch_async(dispatch_get_main_queue(), ^{
//设置验证码按钮
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[self.messageButton setTitle:[NSString stringWithFormat:@"%@秒后重新发送",strTime] forState:(UIControlStateNormal)];
[UIView commitAnimations];
self.messageButton.userInteractionEnabled = NO;
});
count --;
}
});
dispatch_resume(_timer);
2.在storyboard里面拖了一个scrollview,但是奇怪的是无法实现滚动.然而,当我新建一个空的页面,重新拖一个并设置里面的contentSize之后,是可以滚动的.
解决方法:
-(void)viewDidAppear:(BOOL)animated
{
self.scrollView.contentSize =CGSizeMake(320,1000);
}
//或者 这个方法无效的时候 在下面的方法里面设置
-(void)viewDidLayoutSubviews
{
self.scrollView.contentSize =CGSizeMake(320,1000);
}
注意:此处是在viewDidAppear里面,在viewDidLoad和viewWillAppear里面都是无效的.
3. scrollView的属性设置
http://blog.youkuaiyun.com/u012889435/article/details/17523705#
4. arc4random() 比较精确不需要生成随机种子
使用: 通过arc4random() 获取0到x-1之间的整数的代码如下:
int value = arc4random() % x;
获取1到x之间的整数的代码如下:
int value = (arc4random() % x) + 1;
5.iPhone屏幕尺寸、分辨率及适配
http://blog.youkuaiyun.com/phunxm/article/details/42174937
6. 使用xib自定义cell,多个cell类型的时候,不要在一个xib文件中拖拽多个cell进行设置; 因为这样在cell的放回方法里面正常方法判断到xib中有多个cell的时候会崩溃; 一定要使用这种方式的cell取值方法是把xib中的cell按照添加顺序当做数组对象, 按照数组下标取出不同类型的的cell, 具体方法:
mainCell = [[[NSBundle mainBundle]loadNibNamed:@"ZYQMainTableViewCell" owner:self options:nil]objectAtIndex:0];
//有第二种类型cell的时候,并且是第二个拖拽添加的
mainCell = [[[NSBundle mainBundle]loadNibNamed:@"ZYQMainTableViewCell" owner:self options:nil]objectAtIndex:1];
不建议使用这种方法,因为如果cell类型很多的时候,使用数组进行分辨赋值,后期维护的时候容易出现混乱等问题;
如果使用xib的话,比较常用的方法是分别在不同的xib文件中设置每一个cell:
if (indexPath.section == 0 || (indexPath.section == 1 && !(indexPath.row == 0))) { //根据不同的条件选择判断返回那种类型的cell
mainCell = [tableView dequeueReusableCellWithIdentifier:@"firstTableCell" forIndexPath:indexPath];
}else if (indexPath.section == 1 && indexPath.row == 0){
mainCell = [tableView dequeueReusableCellWithIdentifier:@"secondTableCell" forIndexPath:indexPath];
}
mainCell.selectionStyle = UITableViewCellSelectionStyleNone; //取消cell的点击选中状态
return mainCell;
}