欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

iOS 开发百问(3)

程序员文章站 2022-03-31 18:32:50
...
22、解决 messagesent to deallocated instance 0x52cc690 错误
当试图对某个对象进行赋值操作的时候出现这个错误,如:
tfContent.text=bodyText;
此时,你可以打开NSZombieEnable选项,则console会有如下输出:
***-[CFString _isNaturallyRTL]: message sent to deallocated instance 0x52cc690
说明_isNaturallyRTL消息被发送给了一个已经释放了的对象。从上面的语句看,可能是这两个对象:tfContent、bodyText。
你可以打印tfContent或者bodyText的内存地址,看看到底是哪个对象已经被释放掉了:
NSLog(@"tfContent:0x%x",(int) tfContent);
NSLog(@"bodytext:0x%x",(int) bodyText);

结果表明是bodyText被提前释放:

tfContent: 0x52cf160
bodytext: 0x52cc690

在适当的地方对bodyText进行retain,问题解决。
23、 putpkt:write failed: Broken pipe错误
重启设备。
24、.hfile not found
实际上该.h文件并没有被包含进target。选择对应.m文件,点击“ShowUtilities”按钮(在工具条的右端),在Utilities中找到Target Membership,将Target前面的勾去掉,然后再重新勾上。即相当于将该.m文件重新加入target的Buildphase中。
25、 Xcode 4:如何将for iPhone的xib转变为for iPad
在Xcode 3.x中,将xib从iPhone版转变为iPad版,通过Create iPad Version菜单。
但在Xcode 4.x中,这个菜单找不到了。通过一番摸索,笔者发现可以用如下方法将xib转换为iPad版本。
1、修改xib源文件
xib文件其实是一个xml文件。在Project Navigator中,在xib文件上右键,选择“Open As -> Source Code”,即可以源代码方式查看xib文件,找到"com.apple.InterfaceBuilder3.CocoaTouch.XIB"一行,将其改为 "com.apple.InterfaceBuilder3.CocoaTouch.iPad.XIB",即增加了".iPad"。
按下⌘+F,打开搜索栏,点击Replace菜单,将模式改变替换模式。将xib文件中所有"IBCocoaTouchFramework"用 "IBIPadFramework"替换。
按下⌘+S,保存修改。
2、修改xib的视图尺寸
在xib文件上右键,选择“Open As -> Interface Builder – iOS”,用IB模式打开。
选择xib文件中的根视图(UIView),在属性面板中找到Size选项,将其改为Full iPad Screen。

现在,你可以有一个iPad版本的xib了。

26、icon dimensions (0 x 0) don't meet the size requirements.
打开Project的BuildSettings,找到Compress PNG Files,将值设置为No。
或者:
选中该png文件,在FileInspector面板中,找到File Type,将其由 "PNG" 修改为 "Icon".
27、警告: noprevious prototype for function
打开Target->BuildSettings,搜索prototype,将Missing Function ProtoTypes改为NO。
28、CorePlot编译时出现 错误“Command /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/clangfailed with exit code 1”
请将Scheme 从 iOS Device 改为 iPhone 5.0 Simulator。或者将Compiler for C/C++ 改为 LLVM GCC4.2。同时,Core Plot 1.0 不再支持老的 armv6 CPU。
29、使用CABasicAnimation改变UIView的alpha值无效
UIView的alpha值,在CALayer中其实是"opacity",请使用opcity作为keyPath。
30、CorePlost:定制 Axis Label 后,Tick Mark 不显示。
设置Axis 的majorTickLocations 为你想显示 tick mark 的位置。

NSMutableArray*customTickLocations=[[[NSMutableArray alloc]init]autorelease]; 
for(int i=0;i<10;i++){
[customTickLocationsaddObject:[NSNumber numberWithInt:i]];
}
xAxis.majorTickLocations=[NSSetsetWithArray:customTickLocations];

31、定制的UITableViewCell, indentationLevel不能生效
需要在定制的UITableViewCell中实现layoutSubviews方法。

- (void)layoutSubviews
{
[super layoutSubviews];
float indentPoints = self.indentationLevel *self.indentationWidth;
for(UIView *view in self.subviews){
view.frame = CGRectMake(
view.frame.origin.x+indentPoints,
view.frame.origin.y,
view.frame.size.width, 
view.frame.size.height
); 
}
}

以上就是iOS 开发百问(3)的内容,更多相关内容请关注PHP中文网(www.php.cn)!

相关标签: iOS,开发百问