IOS开发问题索引(八)

2022-03-08 14:33:23 浏览数 (2)

全系列文章索引:

IOS开发问题索引(一)

IOS开发问题索引(二)

IOS开发问题索引(三)

IOS开发问题索引(四)

IOS开发问题索引(五)

IOS开发问题索引(六)

IOS开发问题索引(七)

IOS开发问题索引(八)

IOS开发问题索引(九)

1 【SQL】附加数据库5120错误(拒绝访问)处理方法

http://jingyan.baidu.com/article/c1a3101e8b34c2de656debbe.html

右键需要附加的数据库文件,弹出属性对话框,选择安全标签页。找到Authenticated Users用户名。如未找到,进行Authenticated Users用户名的添加。

2 【UI】'-[UITableViewControllerloadView] loaded the "XXX" nib but didn't get a UITableView.'

'-[UITableViewController loadView] loaded the"XXX" nib but didn't get a UITableView.'

解决方法:在头文件中,将所继承的父类UITableViewController 改成 UIViewController。

3 linux/mac vi命令详解

linux/mac vi命令详解

http://blog.csdn.net/youngkingyj/article/details/22713965

4 IOS获取最新设备型号方法

方法:

#import "sys/utsname.h”

struct utsname systemInfo;

uname(&systemInfo);

NSString *deviceString = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];

http://blog.csdn.net/luoyeffcs/article/details/18610839

5 objective-c ASCII NSString转换

objective-c ASCII NSString转换--分享

// NSString to ASCII

NSString *string = @"A";

int asciiCode = [string characterAtIndex: 0]; //65

//ASCII to NSString

int asciiCode = 65;

NSString *string =[NSString stringWithFormat: @"%c",asciiCode]; //A

来源http://blog.sina.com.cn/s/blog_63aaf4690100w981.html

中文字符ASCII码和NSString相互转换

http://www.2cto.com/kf/201309/243443.html

6 【UI】UIButton文字居左显示

UIButton *btn = [[UIButton alloc] init];

btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;

7 【网络】AFNetwork2.0在请求时报错code=-1016和3840

http://blog.csdn.net/huifeidexin_1/article/details/38844535

在进行网络请求时出现-1016是因为只支持text/json,application/json,text/javascript,你可以添加text/html ,一劳永逸的方法是在AFURLResponseSerialization.h里面搜索self.acceptableContentTypes,然后在里面添加@"text/html",@"text/plain"。这样就可以解决-1016的错误了,但是随之而来的是3840错误。

Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed.

(Cocoa error 3840.)" (JSON text did not start with array or object and

option to allow fragments not set.) UserInfo=0x9152780 {NSDebugDescription=JSON

text did not start with array or object and option to allow fragments not set.}

你会发现出现此错误

怎么办呢?

添加如下语句 就可以解决问题了

manger.requestSerializer = [AFHTTPRequestSerializer serializer];

manger.responseSerializer = [AFHTTPResponseSerializer serializer];

是否成功了,成功了吧!但是新问题出现了——编码问题。如果服务器返回a的话,你收到的是<61>,这样怎么能行呢。当你用浏览器去请求时发现响应头Content-Type: text/html;charset=UTF-8是这样的,但是afNetwork 请求是Content-Type:text/plain;charset=ISO-8859-1。为什么pc浏览器访问的和用afNetwork访问的不一致呢? 接着发现其实添加如下二句即可,也不用去修改AFURLResponseSerialization.h 里面的东西

manger.requestSerializer = [AFHTTPRequestSerializer serializer];

manger.responseSerializer = [AFHTTPResponseSerializer serializer];

把收到的responseObject 转换一下编码就OK了。

NSData*doubi= responseObject;

NSString *shabi = [[NSString alloc]initWithData: doubi encoding: NSUTF8StringEncoding];

8 【JSON】NSDictionary与NSString互转

NSString *str = [dataDic JSONRepresentation];

NSDictionary *resultDic = [htmStr JSONValue];

9 【UI】在UIImageView中添加子按钮无法响应事件问题

问题分析:

UIImageView默认是不接受事件响应的userInteractionEnabled=NO,所以用户点击操作在该控件即被截停了,无法往子控件中传递,故需要开启userInteractionEnabled属性为true,以使事件往下传递。

_scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];

_scrollView.delegate = self;

// scrollView.userInteractionEnabled = YES;

[self.view addSubview: _scrollView];

_activityIndicatorView = [MDViewUtility createActivityIndicatorViewInView: self.view];

UIImageView *backImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 200)];

[backImageView setImage: [UIImage imageNamed: @"MyCenter_BackgroundImage"]];

//这一句很重要,不然事件无法往下传递

backImageView.userInteractionEnabled = YES;

[_scrollView addSubview: backImageView];

_myAccountView = [[MDMyAccountView alloc] initWithFrame: CGRectMake(self.view.frame.size.width/2 - 50, 0, 100, 200) WithVM: _myAccountVM];

[backImageView addSubview: _myAccountView];

[_myAccountView.myScoreButton addTarget: self action: @selector(myScoreButtonClicked:) forControlEvents: UIControlEventTouchUpInside];

UITapGestureRecognizer *singleTap1 = [[UITapGestureRecognizer alloc] initWithTarget: self action: @selector(myScoreButtonClicked:)];

singleTap1.delegate = self;

[_myAccountView.myPhotoImageView setUserInteractionEnabled: YES];

[_myAccountView.myPhotoImageView addGestureRecognizer: singleTap1];

UITapGestureRecognizer *singleTap2 = [[UITapGestureRecognizer alloc] initWithTarget: self action: @selector(myScoreButtonClicked:)];

singleTap2.delegate = self;

[_myAccountView.myNeedLoginLabel setUserInteractionEnabled: YES];

[_myAccountView.myNeedLoginLabel addGestureRecognizer: singleTap2];

10 【UI】在二级页面中隐藏Tabbar

在VC初始化时设置属性:

self.hidesBottomBarWhenPushed=YES;

11 Cocoa/Cocoa.hfile not found

Cocoa/Cocoa.h file not found

创建OC类时,有时OC类会自动包含了文件头#import <Cocoa/Cocoa.h>,这时报错:‘Cocoa/Cocoa.h' file not found,这个问题是因为Cocoa/Cocoa.h为OSX的库文件,而不时IOS的库文件,将其修改为#import <UIKit/UIKit.h>问题解决。

不过,所有用到NS***的都要修改为UI***

12 JSONKITisa错误的解决办法

转载:http://blog.csdn.net/hemuhan/article/details/17753453

在开发IOS的时候,好多第三方库使用JSONKIT这个库,在IOS6.0以上的版本编译的话,会提示 Semantic Issue错误。

错误显示:direct access to Objective-C's isa is deprecated in favorof object_getClass()

看资料说是 使用 array->isa 这个弃用的函数,网上查大部分的资料都说要使用object_getClass 和object_setClass来更正。

看到Bee中Demo没有更改这个函数,花费很长时间终于整明白了如果使IOS不报这个错误

从项目中搜索 Direct usage of 'isa' 将 YES(treat as error) 改为NO 就可以了

13 【URL】创建并保存Cookie的方法

NSString*cookieString = [NSString stringWithString: [headers objectForKey: @"Cookie"]];

NSMutableDictionary *cookieProperties = [[NSMutableDictionary alloc]init];

[cookieProperties setValue: cookieString forKey:NSHTTPCookieValue];

[cookieProperties setValue:@"QQCookie"forKey:NSHTTPCookieName];

[cookieProperties setValue:@".QQ.com"forKey:NSHTTPCookieDomain];

[cookieProperties setValue:[NSDate dateWithTimeIntervalSinceNow: 60*60] forKey: NSHTTPCookieExpires];

[cookieProperties setValue:@"/" forKey: NSHTTPCookiePath];

NSHTTPCookie *newcookie = [[NSHTTPCookie alloc] initWithProperties: cookieProperties];

[[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookie: newcookie];

http://ios-iphone.diandian.com/post/2011-09-20/5175529

14 NSDictionary判断空

字典里某个键key的值可能是空数组~~~那这个[dic objectForkey:key]是什么?

你猜会是[NSNull null]?

也可能不是~~~但至少是个空数组。

[[dic objectForkey:key] count]会告诉我们结果。

下面的代码使用了NSNull来判断字典某个键的值是否为空。但是这种判断方法,似乎对于空集合类不大奏效。

id object = nil;

// 判断对象不为空

if(object) {

}

// 判断对象为空

if(object == nil) {

}

// 数组初始化,空值结束

NSArray *array = [[NSArray alloc] initWithObjects:@"First", @"Second", nil];

// 判断数组元素是否为空

NSString *element = [array objectAtIndex:2];

if((NSNull *)element == [NSNull null]) {

}

// 判断字典对象的元素是否为空

NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys: @"iPhone", @"First", @"iPad", @"Second", nil];

NSString *value = [dictionary objectForKey:@"First"];

if((NSNull *)value == [NSNull null]) {

}

15 NSDate格式化输出

NSDate*date = [NSDate dateWithTimeIntervalSince1970: [[MDMyUserInfoEntity shareInstance] birthday]];

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

//设定时间格式,这里可以设置成自己需要的格式

[dateFormatter setDateFormat:@"yyyy-MM-dd"];

//用[NSDate date]可以获取系统当前时间

NSString *currentDateStr = [dateFormatter stringFromDate: date];

16 AFNetworking请求HTTPS时发生code=-1012的错误

AFNetworking 2.0在请求HTTPS资源的时候,总是发生如下错误:

self.securityPolicy = [AFSecurityPolicy policyWithPinningMode: AFSSLPinningModeNone];

//解决“Error Domain=NSURLErrorDomain Code=-1012

"The operation couldn’t be completed.”的问题,AFNetworking 2.0默认在检查SSL证书的时候比较严格self.securityPolicy.allowInvalidCertificates = YES;

解决办法就是允许使用无效的证书。

17 字符串NSString中去掉空格

在ios开发中 stringByTrimmingCharactersInSet函数可以用来去掉字符串中的任意字符。

例如:

NSString *string1 = @" 11 1 ";

NSString *string2 = [string1 stringByTrimmingCharactersInSet [NSCharacterSet whitespaceAndNewlineCharacterSet]];

这个时候string2的结果是"11 1"

(去处空格的时候只是去除字符串中最前和最后的字符。)

【iOS】字符串NSString中去掉空格

http://blog.csdn.net/chenyong05314/article/details/8752654

NSString过滤字符串

http://blog.sina.com.cn/s/blog_5d2698930100wxvw.html

18 AFNetworking请求未发出去返回一堆html代码

网络请求中,域名指向的IP地址错了

19 MBProgressHud显示多行文本

(void) showToastInView:(UIView *)view WithText:(NSString *) text WithDelay:(NSTimeInterval)delay

{

MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo: view animated: YES];

hud.mode = MBProgressHUDModeText;

// hud.labelText = text;

hud.detailsLabelText=text;

hud.detailsLabelFont = [UIFont fontWithName:@"Helvetica" size:16];

hud.detailsLabelColor = [UIColor whiteColor];

hud.margin = 10.f;

hud.yOffset = 0;

hud.alpha = 0.7;

hud.removeFromSuperViewOnHide = YES;

[hudhide:YES afterDelay:delay];

}

20 nestedpush animation can result in corrupted navigation bar

nested push animation can result in corrupted navigation bar.

Finishing up a navigation transition in an unexpected state.Navigation Bar subview tree might get corrupted.

【iphone】返回崩溃:nested pop animation canresult in corrupted navigation bar nested pop animation can re

http://blog.csdn.net/lengshengren/article/details/12616217

0 人点赞