仅在 iOS7 上崩溃
+(PageSection *)initwithPageSection:_anchor withHeader:_subHeader withDetails:_text withPhoneNumberIfValidid)_phoneNo
{
const char *tempAnchor = [_anchor cStringUsingEncoding:[NSString defaultCStringEncoding]];
const char *tempSubHeader = [_subHeader cStringUsingEncoding:[NSString defaultCStringEncoding]];
const char *tempText = [_text cStringUsingEncoding:[NSString defaultCStringEncoding]];
const char *tempPhoneNo = [_phoneNo cStringUsingEncoding:[NSString defaultCStringEncoding]];
NSData *anchorData = [NSData dataWithBytes:tempAnchor length:[_anchor length]];
NSData *subHeaderData = [NSData dataWithBytes:tempSubHeader length:[_subHeader length]];
NSData *textData = [NSData dataWithBytes:tempText length:[_text length]];
NSData *phoneData = [NSData dataWithBytes:tempPhoneNo length:[(NSString *)_phoneNo length]];
PageSection *p =[[PageSection alloc]init];
p.anchorTag=[[NSString alloc] initWithData:anchorData encoding:NSUTF8StringEncoding];
p.subHeader=[[NSString alloc] initWithData:subHeaderData encoding:NSUTF8StringEncoding];
p.text=[[NSString alloc] initWithData:textData encoding:NSUTF8StringEncoding];
p.phoneNo=[[NSString alloc] initWithData:phoneData encoding:NSUTF8StringEncoding];
return p;
}
使用崩溃的这一行:NSData *textData = [NSData dataWithBytes:tempText length:[_text length]];
有什么想法吗??
Best Answer-推荐答案 strong>
实际上它返回 NULL 但仅适用于 iOS7 const char *tempText = [_text cStringUsingEncoding:[NSString defaultCStringEncoding]]; NSLog(@"tex: %s", tempText);
这就是它崩溃的原因
关于ios - nsdata dataWithBytes 在 iOS7 上导致崩溃,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/20143700/
|