ios 开发常用技巧
1.TableView不显示没内容的Cell怎么办?
self.tableView.tableFooterView = [[UIView alloc] init];
2.自定义了leftBarbuttonItem左滑返回手势失效了怎么办?
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]
initWithImage:img
style:UIBarButtonItemStylePlain
target:self
action:@selector(onBack:)];
self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;
(最好在父控制器里写)
3.ScrollView莫名其妙不能在viewController划到顶怎么办?
self.automaticallyAdjustsScrollViewInsets = NO;
4.键盘事件写的好烦躁,都想摔键盘了,怎么办?
使用IQKeyboardManager(github上可搜索)
5.1、禁止手机睡眠
[UIApplication sharedApplication].idleTimerDisabled = YES;
6.隐藏某行cell
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
// 如果是你需要隐藏的那一行,返回高度为0
if(indexPath.row == YouWantToHideRow)
return 0;
return 44;
}// 然后再你需要隐藏cell的时候调用
[self.tableView beginUpdates];
[self.tableView endUpdates];
7.禁用button高亮
button.adjustsImageWhenHighlighted = NO;
或者在创建的时候
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
8.画水印
// 画水印
- (void) setImage:(UIImage *)image withWaterMark:(UIImage *)mark inRect:(CGRect)rect
{
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 4.0)
{
UIGraphicsBeginImageContextWithOptions(self.frame.size, NO, 0.0);
}
//原图
[image drawInRect:self.bounds];
//水印图
[mark drawInRect:rect];
UIImage *newPic = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
self.image = newPic;
}
9.cell去除选中效果
cell.selectionStyle = UITableViewCellSelectionStyleNone;
10.cell点按效果
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
上一篇: 记录自己的第一次Python编程
下一篇: PHP实现异步调用方法研究与分享