首页 文章 精选 留言 我的

精选列表

搜索[ios],共10000篇文章
优秀的个人博客,低调大师

【iOS】 含tableView的ViewController基类的实现

上篇博客写了ViewController的基类的实现,这篇博客主要写在BaseViewController的基础上实现一个含tableView控件的基类的实现,主要给包含tableView的页面来继承。 BaseTableViewViewController.h代码: #import "BZBaseViewController.h" #import "BZBaseTableViewCell.h" @interface BZBaseTableViewViewController : BZBaseViewController<UITableViewDelegate,UITableViewDataSource> @property(nonatomic,strong) UITableView * tableView; @property(nonatomic,strong) NSArray * dataSource; -(void)setupTableView; @end BaseTableViewViewController.m代码: #import "BZBaseTableViewViewController.h" @interface BZBaseTableViewViewController () @end @implementation BZBaseTableViewViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. } -(void)setupTableView{ [self.view addSubview:self.tableView]; } #pragma mark - UITableViewDelegate & UITableViewDataSource -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return 1; } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return 0; } -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return 0.0; } -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{ return 0.001; } -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{ return 0.001; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ BZBaseTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"ID"]; if (!cell) { cell = [[BZBaseTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"ID"]; } return cell; } #pragma mark - lazy -(UITableView *)tableView{ if (!_tableView) { _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - self.mNavigationbarHeight) style:UITableViewStyleGrouped]; _tableView.delegate = self; _tableView.dataSource = self; _tableView.showsVerticalScrollIndicator = NO; _tableView.backgroundColor = [UIColor clearColor]; _tableView.separatorStyle = UITableViewCellSeparatorStyleNone; _tableView.estimatedRowHeight = 0; _tableView.estimatedSectionHeaderHeight = 0; _tableView.estimatedSectionFooterHeight = 0; } return _tableView; } @end 项目中包含tableView的ViewController都可以继承自该类,重写tableView的代理方法就可以实现相应的功能。 另外,tableView的实现离不开tableViewCell,所以我们也可以写一个BaseTableViewCell,让其他的tableViewCell来继承。 BaseTableViewCell.h代码: #import <UIKit/UIKit.h> @interface BZBaseTableViewCell : UITableViewCell -(void)setupUI; @end BaseTableViewCell.m代码: #import "BZBaseTableViewCell.h" @implementation BZBaseTableViewCell - (void)awakeFromNib { [super awakeFromNib]; // Initialization code } -(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{ self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; self.selectionStyle = UITableViewCellSelectionStyleNone; if (self) { [self setupUI]; } return self; } -(void)setupUI{ } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; // Configure the view for the selected state } @end 继承自BaseTableViewCell的子类直接实现-(void)setupUI;方法即可实现自定义的cell界面。

优秀的个人博客,低调大师

iOS 给字典中插入nil的几种情景

NSString *str = nil; NSDictionary *dic = @{@"key":str}; //zs20171220 会崩溃'*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0] 字面量添加nil 会崩溃 NSString *str = nil; NSDictionary *dicParam = [[NSDictionary alloc] initWithObjectsAndKeys:@"",@"key1",str,@"key2",nil]; NSLog(@"dicParam____%@",dicParam[@"key2"]);//zs20171220 value 值可以为nil,但是这个时候nil意味着结束添加了 NSLog(@"dicParam____%@",dicParam.allKeys); NSLog(@"dicParam____%@",dicParam[@"key1"]);//zs20171220 key 不能设置成nil 否则会崩溃 NSString *str = nil; NSMutableDictionary *dicMutable = [NSMutableDictionary dictionaryWithCapacity:0]; [dicMutable setValue:str forKey:@"key1"];//zs20171220 插入nil 不会崩溃 [dicMutable setValue:@"ddd" forKey:@"key2"]; [dicMutable setValue:nil forKey:@"key3"];//zs20171220 插入nil 不会有这个key 和值 NSLog(@"___%@",dicMutable); 20180925+总结: 用字面量语法创建数组时要注意,若数组元素中有nil, 则会抛出异常,因为字面量语法实际上只是一种“语法糖”(syntactic sugar),其效果等于是先创建了一个数组,然后把方括号内的所有对象都加到这个数组中。 eg: NSArray *arrayA = [NSArray arrayWithObjects:obj1,obj2,obj3,nil]; NSArray *arrayB = @[obj1,obj2,obj3]; 如果obj1与obj3都指向了有效的OC对象,而obj2是nil,按字面量语法创建数组arrayB时会抛出异常。 arrayA 虽然能创建出来,但是其中却只含有obj1一个对象,原因在于arrayWithObjects:方法会依次处理各个参数,直到发现nil为止,由于obj2是nil,所以该方法会提前结束。 重点(敲黑板): 这个微妙的差别说明,使用字面量语法更为安全。抛出异常令应用程序终止执行,这比创建好数组之后发现元素个数少了要好。

优秀的个人博客,低调大师

ios创建画笔的样例(双笔画效果)

定义一个UIView:主要是在这个View里面加一个UIImageView,绘图都在这个UIImageView里面进行 @property(nonatomic) CGPoint prePoint; //手指在进入move事件之前的那个点 @property(nonatomic) CGPoint oppsitePoint; //手指在进入move事件之前的那个点 @property(nonatomic, retain) UIImageView* drawImage; - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { // Initialization code self.drawImage = [[UIImageView alloc] initWithImage:nil]; self.drawImage.frame = self.frame; [self addSubview:_drawImage]; } return self; } 然后处理手指的事件 #pragma mark - deal touch -(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ NSLog(@"touchesBegan"); //以下两句知道手指在屏幕上的点的信息 UITouch* touch = [touches anyObject]; CGPoint point = [touch locationInView:self]; if (touch) { self.prePoint = point; _oppsitePoint = point; _oppsitePoint.x = 320.0f - point.x; } } -(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{ NSLog(@"touchesMoved"); UITouch* touch = [touches anyObject]; if (touch) { CGPoint point = [touch locationInView:self]; UIGraphicsBeginImageContext(self.frame.size); [_drawImage.image drawInRect:CGRectMake(0, 0, _drawImage.frame.size.width, _drawImage.frame .size.height)]; CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound); CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 2.0f); CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(),0.314, 0.486, 0.859, 1.0); CGContextBeginPath(UIGraphicsGetCurrentContext()); CGContextMoveToPoint(UIGraphicsGetCurrentContext(), _prePoint.x, _prePoint.y); CGContextAddQuadCurveToPoint(UIGraphicsGetCurrentContext(), _prePoint.x, _prePoint.y, point.x, point.y); CGContextMoveToPoint(UIGraphicsGetCurrentContext(), _oppsitePoint.x, _oppsitePoint.y); CGContextAddQuadCurveToPoint(UIGraphicsGetCurrentContext(), _oppsitePoint.x, _oppsitePoint.y, 320.0f - point.x, point.y); // CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), point.x, point.y); CGContextStrokePath(UIGraphicsGetCurrentContext()); _drawImage.image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); _prePoint = point; _oppsitePoint = point; _oppsitePoint.x = 320.0f - point.x; } } -(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{ NSLog(@"touchesEnded"); //这段的作用是假设在屏幕上点击能够画出点 UIGraphicsBeginImageContext(self.frame.size); [_drawImage.image drawInRect:CGRectMake(0, 0, _drawImage.frame.size.width, _drawImage.frame .size.height)]; CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound); CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 3.0f); CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(),0.314, 0.486, 0.859, 1.0); CGContextBeginPath(UIGraphicsGetCurrentContext()); CGContextMoveToPoint(UIGraphicsGetCurrentContext(), _prePoint.x, _prePoint.y); CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), _prePoint.x, _prePoint.y); CGContextStrokePath(UIGraphicsGetCurrentContext()); _drawImage.image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); self.isTouch = NO; } 以下为效果图 本文转自mfrbuaa博客园博客,原文链接:http://www.cnblogs.com/mfrbuaa/p/5174654.html,如需转载请自行联系原作者

优秀的个人博客,低调大师

电商直播ios app耗电发热比较评测

比较app: 优品惠直播,聚美优品直播,淘宝直播,京东直播 前提: 1、开启手机电池电量log记录; 2、把手机后台其他app都清退,仅保留当前评测app; 3、同款手机iphone6plus; 4、评测时不连接电源线,用wifi方式; 5、每个测试app看10分钟直播,取log记录数据,记录电池耗电量比值。 结果: 第一名:淘宝直播:0.66(流畅) 第二名:优品惠直播硬解码:0.7075(流畅) 第三名:京东直播: 0.71(当天进直播间很卡,估计直播系统有问题) 第四名:优品惠直播:0.75(流畅) 第五名:聚美优品直播: 0.775(流畅) 开启硬件加速后手机耗电量会有明显降低,机身温度也会比较理想,但画面大幅运动时马赛克感会比软编码要明显。 本文转自ljianbing51CTO博客,原文链接:http://blog.51cto.com/ljianbing/1930291,如需转载请自行联系原作者

优秀的个人博客,低调大师

iOS UIWebView 获取内容实际高度,关闭滚动效果

近期做东西,将 UIWebView 嵌套在 UIScrollView 里,由 UISCrollView 控制滚动,需要使 UIWebView 的高度同内容高度一致,网上搜索的到代码: <!--lang:cpp-->htmlHeight=[webViewstringByEvaluatingJavaScriptFromString:@"document.body.offsetHeight"]; 这段代码是无效的,body 获取到的 offsetHeight,为显示区域的高度,因此修改为: <!--lang:cpp-->htmlHeight=[webViewstringByEvaluatingJavaScriptFromString:@"document.body.scrollHeight"]; scrollHeight 为网页内容的实际高度。 之后,自然需要关闭 UIWebView 的滚动效果,否则将会影响整体页面滚动,代码如下: <!--lang:cpp-->UIScrollView*tempView=(UIScrollView*)[webView.subviewsobjectAtIndex:0]; tempView.scrollEnabled=NO; 修改 UIScrollView的内容高度。 <!--lang:cpp-->scrollView.contentSize=CGSizeMake(width,height); 本文转自ljianbing51CTO博客,原文链接:http://blog.51cto.com/ljianbing/1744117 ,如需转载请自行联系原作者

资源下载

更多资源
优质分享App

优质分享App

近一个月的开发和优化,本站点的第一个app全新上线。该app采用极致压缩,本体才4.36MB。系统里面做了大量数据访问、缓存优化。方便用户在手机上查看文章。后续会推出HarmonyOS的适配版本。

Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

用户登录
用户注册
修改密码
忘记密码