IOS 开发技巧,小细节,注意事项
2015-09-08 00:00
706 查看
// textFieldShouldReturn 函数写了,但是按键到 return 无法让键盘消失
因为你的文本框没有添加委托。添加委托的方法,右键文本框,把 outlets 下的+拉到 file's owner上就可以了。 或者在加载事件中添加 textFeild.delegate=self;
// numberOfRowsInSection 问题
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return 1; // 当返回值为 0 时,- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {} 不会渲染执行
}
// tableView 没有数据
可能是 tableView没有绑定事件,或者在加载事件中添加 self.tableView.delegate = self;self.tableView.dataSource = self;
//添加事件对象
self.tableView.target = self;
//单击方法
self.tableView.action = @selector(singleClickAction:);
//允许空 Selection
self.tableView.allowsEmptySelection = YES;
//webView 载入网页时 页面过大,不自适应,可通过下面代码使 webview 自适应大小
[webView setScalesPageToFit:YES]
//下面两种可以隐藏键盘
1、[view endEditing:YES] 这个方法可以让整个view取消第一响应者,从而让所有控件的键盘隐藏。
2、[textFiled resignFirstResponder] 这个则是比较常用的让某个textFiled的键盘隐藏。
//点击 view 空白 触发
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
[view endEditing:YES];
//[textFiled resignFirstResponder];
}
//获取系统版本号为 8.0 以上
([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
//手动调用 tableView 的点击事件
[self tableView:_tableView didSelectRowAtIndexPath:[NSIndexPath indexPathForRow:2 inSection:0]];
// 设置 view 圆角
view.layer.masksToBounds=YES;// [_label.layer setMasksToBounds:YES];
view.layer.cornerRadius = 5;
//页面传值方式
(属性,代理,block,单例,通知)
//window 覆盖状态栏
UIWindow* window = [uiwindow new];
window.windowLevel = UIWindowLevelStatusBar + 1000;
[window addSubview:self];
//iOS之用 NSTimer 避免倒计时按钮的文字闪烁的办法
将UIButton的类型由system改为custom
//通过文件路径读取图片
NSString *path =[[NSBundle mainBundle] pathForResource:@"map" ofType:@"png"];
UIImage *image = [UIImage imageWithContentsOfFile:path];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
因为你的文本框没有添加委托。添加委托的方法,右键文本框,把 outlets 下的+拉到 file's owner上就可以了。 或者在加载事件中添加 textFeild.delegate=self;
// numberOfRowsInSection 问题
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return 1; // 当返回值为 0 时,- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {} 不会渲染执行
}
// tableView 没有数据
可能是 tableView没有绑定事件,或者在加载事件中添加 self.tableView.delegate = self;self.tableView.dataSource = self;
//添加事件对象
self.tableView.target = self;
//单击方法
self.tableView.action = @selector(singleClickAction:);
//允许空 Selection
self.tableView.allowsEmptySelection = YES;
//webView 载入网页时 页面过大,不自适应,可通过下面代码使 webview 自适应大小
[webView setScalesPageToFit:YES]
//下面两种可以隐藏键盘
1、[view endEditing:YES] 这个方法可以让整个view取消第一响应者,从而让所有控件的键盘隐藏。
2、[textFiled resignFirstResponder] 这个则是比较常用的让某个textFiled的键盘隐藏。
//点击 view 空白 触发
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
[view endEditing:YES];
//[textFiled resignFirstResponder];
}
//获取系统版本号为 8.0 以上
([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
//手动调用 tableView 的点击事件
[self tableView:_tableView didSelectRowAtIndexPath:[NSIndexPath indexPathForRow:2 inSection:0]];
// 设置 view 圆角
view.layer.masksToBounds=YES;// [_label.layer setMasksToBounds:YES];
view.layer.cornerRadius = 5;
//页面传值方式
(属性,代理,block,单例,通知)
//window 覆盖状态栏
UIWindow* window = [uiwindow new];
window.windowLevel = UIWindowLevelStatusBar + 1000;
[window addSubview:self];
//iOS之用 NSTimer 避免倒计时按钮的文字闪烁的办法
将UIButton的类型由system改为custom
//通过文件路径读取图片
NSString *path =[[NSBundle mainBundle] pathForResource:@"map" ofType:@"png"];
UIImage *image = [UIImage imageWithContentsOfFile:path];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
相关文章推荐
- iOS Cocoa编码规范
- iOS开发系列课程(07) --- 分栏视图控制器
- iOS开发系列课程(06) --- 常用控件介绍
- iOS---iPad开发及iPad特有的特技
- ios8绘图方法小记touchesBegan&touchesMoved
- iOS开发 - 汉字转拼音
- IOS 中的页面跳转(navigaitonController)+带自动返回
- iOS开发:Delegate、Notification和KVO的联系与区别
- iOS开发:MVC(模型-视图-控制器)详解
- iOS编程:学习篇(十二)
- iOS数据持久化
- 新浪微博自定制TabBar
- IOS己见之NSDate
- iOS学习篇章3--SEL与@selector
- iOS 笔记六: 协议 Protocols
- IOS开发指南学习——数据持久化(Core Data)
- Installation Failure Troubleshooting for iOS
- 问题:In IOS8 wakeups limit
- iOS应用性能调优的25个建议和技巧
- IOS 技术进阶 —— RunLoop 原理和核心机制