判断字符串中是否含有某一字符
if([roadTitleLab.text rangeOfString:@"qingjoin"].location !=NSNotFound)
//_roaldSearchText
{
NSLog(@"yes");
} else {
NSLog(@"no");
}
修改textField的placeholder字体的颜色和大小
textField.placeholder = @"username is in here!"; [textField setValue:[UIColor redColor] forKeyPath:@"_placeholderLabel.textColor"];
[textField setValue:[UIFont boldSystemFontOfSize:16] forKeyPath:@"_placeholderLabel.font"];
去用来隐藏navigationBar
self.navigationController.navigationBarHidden = YES;
去除NavigationBar下面的线
self.navigationController.navigationBar.barStyle = UIBaselineAdjustmentNone;
cell的单选效果
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
GDFollowUpTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"FollowUp"];
cell.selectionStyle = UITableViewCellSelectionStyleNone;//点击时无色
cell.message = self.array[indexPath.row][@"CONTENT"];
if (self.chooseFlag == indexPath.row){//判断是否被选中
cell.okButton.hidden = NO;
} else {
cell.okButton.hidden = YES;
}
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
self.chooseFlag = indexPath.row;
[self.tableView reloadData];
}
改变滑动删除的文字内容
-(nullable NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString * string = @"设置";
return string;
}
collectionView cell上下左右边距
return UIEdgeInsetsMake(1, 13, 1, 1);
获取当前版本号
//获取当前版本号
NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
NSString *app_Version = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
判断switch是否处于开闭状态
cell.switch.on = YES;
cell.switch.on = NO;
判断字典中元素为空
NSDictionary * dic;
if([dic count] == 0)
{
//....
}
判断后台返回的对象是否为空的判断方法
if (responseObject isEqual:[NSNull null])
当url地址有问题为nil时的解决方案
解决 代码如下:
NSString * url = [NSString stringWithFormat:@"网址"];
NSString * newUrl = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
今天在实现判断星星数量的时候遇到一个问题,从而引出接触到一个新的概念,我姑且称之为控件数组。就是在某些时候存在大量同类型控件关联大量输出口需要使用类似collection但又不能使用的时候的一种替换方案。
使用方法:
1.关联一个输出口,在Outlet处选择Outlet Collection,然后填写名称,即声明成功一个该控件类型的数组
2.之后把大量相同的类型控件都关联到该输出口合并,从而组成数组中的元素,使用时按照普通数组的使用方法即可
代码demo:
@property (strong, nonatomic) IBOutletCollection(UIImageView) NSArray *xing;
NSInteger score = [self.detailePlan[@"DIFFICULTY"] integerValue];
for (int i = 0; i < 5; i++) {
UIImageView * imageView = (UIImageView *)self.xing[i];
if (i < score) {
imageView.hidden = NO;
} else {
imageView.hidden = YES;
}
// imageView.hidden = NO;
}
跳转到一个tabBar上
TabBarViewController * tabBar = [[TabBarViewController alloc] init];
[self presentViewController:tabBar animated:YES completion:^{
}];
当某个cell在该tableView中只存在一个的时候,不需要使用复用
解决cell很卡
是因为在加载网络图片或其他东西的时候使用了同步方法,更换为异步
清空数组的方法 技巧
Xcode中,会有两种Array, NSArray以及NSMutableArray
在清空的过程中,千万不要使用 Array == nil; 这样不仅清空了数组,同时也把memory释放了,这个object就不存在了
正确的做法是
利用
removeAllObjects; 这样就可以得到想要的效果了
使用nil将会删除整个数组:
[NSArray removeAllObjects];
网友评论