首页 技术 正文
技术 2022年11月11日
0 收藏 306 点赞 3,104 浏览 4169 个字

1:用UIImageView作为背景,但直接把按钮或者UITextField放在上面无法相应事件。

解决办法:UIImageView默认的UserInteractionEnabled是NO,把它修改成YES,或者可以直接在XCODE上面的view有个属性勾选User Interaction Enabled遇到的场景(在滚动视图里面放一个图片视图,在图片视图上又放置一个按键,发现一直没有响应效果);

2:AFnetWorking报”Request failed: unacceptable content-type: text/html”

对应到自己的项目里面,我用的是AFNetworking这套网络请求包,需要改的是:AFURLResponseSerialization.m文件223行:self.acceptableContentTypes = [NSSetsetWithObjects:@"application/json", @"text/html",@"text/json",@"text/javascript", nil];加上@"text/html",部分,其实就是添加一种服务器返回的数据格式。

3:NSMutableArray和NSArray的相互转换

// NSArray --> NSMutableArray
NSMutableArray *myMutableArray = [myArray mutableCopy]; // NSMutableArray --> NSArray
NSArray *myArray = [myMutableArray copy];

4:自定义系统导航条上面的返回按钮,以及文字,右侧收藏按钮

 //中间标题
UILabel *navLabel = [[UILabel alloc] initWithFrame:CGRectMake(, , , )];
navLabel.text = @"团购详情";
navLabel.textColor = [UIColor whiteColor];
navLabel.font = [UIFont systemFontOfSize:];
navLabel.textAlignment = NSTextAlignmentCenter;
self.navigationItem.titleView = navLabel; //右边收藏按钮
UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
rightButton.frame = CGRectMake(, , , );
[rightButton setBackgroundImage:LOAD_IMAGE(@"meishoucang") forState:UIControlStateNormal];
[rightButton addTarget:self action:@selector(doShouCang) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithCustomView:rightButton];
self.navigationItem.rightBarButtonItem = rightItem; //左边返回按钮
UIButton *fanHuiButton = [UIButton buttonWithType:UIButtonTypeCustom];
fanHuiButton.frame = CGRectMake(, , , );
[fanHuiButton setBackgroundImage:LOAD_IMAGE(@"fanhuijiantou") forState:UIControlStateNormal];
[fanHuiButton addTarget:self action:@selector(doFanHui) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:fanHuiButton];
self.navigationItem.leftBarButtonItem = leftItem;导航条上的title字体, 字号 可以这么定义,完全使用系统的
[self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor colorWithRed:1.0/ green:1.0/ blue:1.0/ alpha:], UITextAttributeTextColor,[UIColor clearColor],UITextAttributeTextShadowColor,[UIFont systemFontOfSize:],UITextAttributeFont,nil]];

5:清理UITableView底部空的列

self.tableView.tableFooterView = [[UIView alloc] init];

6:如何隐藏navigation跳转后的头部右键

//隐藏头部左边的返回
self.navigationItem.hidesBackButton=YES;
//隐藏头部右边
self.navigationItem.rightBarButtonItem.customView.hidden=YES;

7:如要给UICollectionViewController视图设置背景图

UIImage *image=[UIImage imageNamed:@"AppBg"];
self.collectionView.layer.contents=(id)image.CGImage;

8:可以在其它地方修改rootViewController

UIWindow *window = [UIApplication sharedApplication].keyWindow;
window.rootViewController = [[HVWTabBarViewController alloc] init];

9:新浪微博授权登录报Warning: Attempt to present on whose view is not in the window hierarchy!

 IntroductoryViewController *introductory=[mainStoryboard instantiateViewControllerWithIdentifier:@"introductoryview"];
UINavigationController *rootNavigationController=[[UINavigationController alloc] initWithRootViewController:introductory];
self.window.rootViewController=rootNavigationController;主要问题是a跳转到b,然后b放一个授权新浪微博的按键,增加一个UINavigationController,然后在a跳转到b时用nav跳转: UIStoryboard *mainStoryboard=[UIStoryboard storyboardWithName:@"Main" bundle:nil];
LoginViewController* loginviewControll=[mainStoryboard instantiateViewControllerWithIdentifier:@"loginviewcontroller"];
[self.navigationController pushViewController:loginviewControll animated:YES];

10:在引入第三方TcweiboSDK报linker command failed with exit code1(use -v to see invocation)

是因为重复引入libTCWeiboSDK这个类库,TARGETS-PROJECT-Build Phases-Link Binary With Libraries中,有三个libTcweiboSDK,可以删除libTCWeiboSDK-I386.a

11:NSUserDefaults存放民NSDictionary

注意:NSUserDefaults支持的数据类型有NSString、 NSNumber、NSDate、 NSArray、NSDictionary、BOOL、NSInteger、NSFloat等系统定义的数据类型。
本次遇到的问题:当NSDictionary里面的值为null时,要写入NSUserDefaults会报异常(attempt to insert non-property list object);
解决方式:把字典中的值进行过滤处理,为空的转化成字符串的空值;代码如下(创建一个扩展类):@implementation NSDictionary(Common)
-(NSDictionary *) changeDictionaryNotNill
{
NSMutableDictionary *muResult=[[NSMutableDictionary alloc]init];
NSEnumerator *enumerator=[self keyEnumerator];
id key;
while ((key=[enumerator nextObject])) {
id value=[self objectForKey:key];
if ((NSNull *)value==[NSNull null]) {
[muResult setObject:@"" forKey:key];
}
else
{
[muResult setObject:value forKey:key];
}
}
return muResult;
}
@end
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,086
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,561
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,410
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,183
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,820
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,903