1、选中某个元素:
[_collectionView selectItemAtIndexPath:indexPath animated:NO scrollPosition:UICollectionViewScrollPositionNone];
cell.selected = YES;
[self collectionViewDidSelectItem:cell];//自定义选中样式,上面的两行代码必须都加上。这个是自定义方法,因为上面的方法不会自动触发代理方法:didSelectItemAtIndexPath
2、取消选中某个元素
[_collectionView deselectItemAtIndexPath:indexPath animated:NO];
cell.selected = NO;
[self collectionViewDidDeselectItem:cell];//自定义非选中样式,上面的两行代码必须都加上。这个是自定义方法,因为上面的方法不会自动触发代理方法:didDeselectItemAtIndexPath
每月存档: 2015年12月
UITableView默认选中第一行,代码如下:
NSIndexPath *indexPath=[NSIndexPath indexPathForRow:0 inSection:0];
[_tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
注意,调用以上方法并不会自动触发代理方法:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath。
开发中可能会遇到UITableView每一行的高度不一样,可以根据每行不通的内容返回不同高度,修改UITableViewDelegate代理方法如下:
– (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [self tableView:tableView cellForRowAtIndexPath:indexPath];
return cell.frame.size.height;
}
开发中需要设置用户头像显示为圆角,代码如下:
headimg.layer.masksToBounds=YES;
headimg.layer.cornerRadius=headimg.frame.size.width/2.0f; //设置为图片宽度的一半出来为圆形
headimg.layer.borderWidth=2.0f; //边框宽度
headimg.layer.borderColor=[[UIColor whiteColor] CGColor];//边框颜色
项目需要,一个界面中有一个按钮,点击可以切换tabBarController的子界面,代码如下,记录下:
[self.tabBarController setSelectedIndex:2];
原创内容转载请保留出处GEEK笔记(http://www.geekapp.cn/)。
UIStoryboard *secondStroyBoard=[UIStoryboard storyboardWithName:@"LoginRegister" bundle:nil];
UIViewController *login=[secondStroyBoard instantiateViewControllerWithIdentifier:@"login"];
[self presentViewController:login animated:YES completion:nil];
说明:
1、@”LoginRegister”为Storyboard文件名
2、@”login”为Storyboard id
原创内容转载请保留出处GEEK笔记(http://www.geekapp.cn/)。