美文网首页
平时遇到问题和一些小技巧2

平时遇到问题和一些小技巧2

作者: 别叫我超人 | 来源:发表于2016-05-31 17:35 被阅读110次

1.条件编译的宏定义

如果是1 显示颜色 0没有颜色

如果全局不需要打印 把1改为0   (可以找到打印对象所在的类 和所在的行)

#if1

#define NSLog(FORMAT, ...) fprintf(stderr,"[%s:%d行] %s\n",[[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], __LINE__, [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);

#else

#define NSLog(FORMAT, ...) nil

#endif

2.tableview的tableHeaderView上放一个web view时 动态的改变tableHeaderView的frame

[webView sizeToFit];

CGRect newFrame = headerView.frame;

newFrame.size.height = newFrame.size.height + webView.frame.size.height;

headerView.frame = newFrame;

[self.tableView setTableHeaderView:headerView];

效果可以实现,但是过度可能显的生硬,可以进行下面的操作,加一点动画

[self.tableView beginUpdates];

[self.tableView setTableHeaderView:headerView];

[self.tableView endUpdates];

3.获取当前时间

NSDate*  senddate=[NSDate date];

NSDateFormatter  *dateformatter=[[NSDateFormatter alloc] init];

[dateformatter setDateFormat:@"YYYY/MM/dd HH:mm:ss"];

NSString*  locationString=[dateformatter stringFromDate:senddate];

NSLog(@"locationString:%@",locationString);

4.手势和button冲突时

_panGestureRecognizer.cancelsTouchesInView = NO;

5.求数组中所有元素的和,平均值

NSNumber *sum = [testArray valueForKeyPath:@"@sum.floatValue"];

NSNumber *avg = [testArray valueForKeyPath:@"@avg.floatValue"];

6.调用系统的通讯录 相册时显示的是英文的解决办法

在info.plist里面添加 Localized resources can be mixed YES(表示是否允许应用程序获取框架库内语言)即可解决这个问题

7.webview的post请求方式

NSURL *url = [NSURL URLWithString: @"http://www.****.com"];

NSString *body = [NSString stringWithFormat: @"email=%@&password=%@&amount=%@",@"a@a.com",@"1",@"12"];

NSMutableURLRequest *request = [[NSMutableURLRequest alloc]initWithURL: url];

[request setHTTPMethod: @"POST"];

[request setHTTPBody: [body dataUsingEncoding: NSUTF8StringEncoding]];

[WebView loadRequest: request];

相关文章

网友评论

      本文标题:平时遇到问题和一些小技巧2

      本文链接:https://www.haomeiwen.com/subject/yyocdttx.html