IOS 小细节,注意事项

// 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;



你可能感兴趣的:(IOS 小细节,注意事项)