Project Settings的设置bug

问题描述
帮客户的iPad安装AD demo,机器SDK是4.2.1,客户iPad SDK是3.2,直接developer debug不成功。

问题分析
把“Project Settings”的"Build"选项卡里的"Base SDK"设置为"Latest iOS"(最高),并把"iOS Deployment Target"设置为"iOS 3.0"(最低)。

问题解决
网上查了下,看到一老外的解决办法,如下:

I believe the only requirement is that you edit and resave the info.plist file. I editted to 1.7, saved, and then back to 1.0 and it worked fine.

It may be that XCode is binding in additional details from the build settings at the time of packaging and since the info.plist hadn't changed those additional bindings did not get attached. If this is the case I would consider it a bug.

我也认为是一个iOS的Bug,只有修改info.plist才会导致project settings设置生效。

UIImageView frame设置顺序问题

问题描述:
今天做AD ipad版展示功能点,背景不显示。

问题分析:
检查代码,其他都没什么问题。发现设置frame在设置image之前。

代码如下:

UIImage *backgroundImage=[UIImage imageNamed:BACKGROUND_FILE_NAME];
_backgroundImageView=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, backgroundImage.size.width, backgroundImage.size.height)];
_backgroundImageView.image=backgroundImage;

问题解决:
把设置frame代码放置在设置frame之后,一切安逸了。

代码如下:

_backgroundImageView=[[UIImageView alloc] init];
UIImage *backgroundImage=[UIImage imageNamed:BACKGROUND_FILE_NAME];
_backgroundImageView.image=backgroundImage;
_backgroundImageView.frame=CGRectMake(0, 0, backgroundImage.size.width, backgroundImage.size.height);

UIButton click不触发问题

问题描述:
今天做AD的ipad版展示功能点,为UIButton加入点击事件后,没有调用效果。

问题分析:
代码如下:

[button addTarget:self action:@selector(groupClicked:) forControlEvents:UIControlEventTouchUpInside];

- (void)objectClicked:(id)vSender
{
}

objectClicked方法没有被调用。查了下,addSubView等都没问题。突然想到父类是UIView,frame没有设定过。

问题解决:
设定frame:self.frame=CGRectMake(0,0,768,961);

一切安逸了。

不同iOS SDK对事件调用支持不同

问题描述:

今天做AD杂志(iPad)LEGO功能点,需要在UIScrollView中让UIView移动。加了正确代码,结果却不好。

结果是这样的:点击不移动,运行touchesBegan和touchesEnded,一切正常。但是点下移动释放,touchesBegan会100%运行,然后三两个touchesMoved,move效果也跟不上,touchesEnded也没有触发。

在UIView用了如下代码实现:

#pragma mark --

#pragma mark touch

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

{

NSLog(@"touchesBegan");

UITouch *touch = [touches anyObject];

UIScrollView *parentView = (UIScrollView *)[[[touch view] superview]superview];

parentView.scrollEnabled=NO;

// Calculate and store offset, and pop view into front if needed

CGPoint pt = [[touches anyObject] locationInView:self];

startLocation = pt;

}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event

{

NSLog(@"touchesMoved");

// Calculate offset

CGPoint pt = [[touches anyObject] locationInView:self];

float dx = pt.x - startLocation.x;

float dy = pt.y - startLocation.y;

CGPoint newcenter = CGPointMake(self.center.x + dx, self.center.y + dy);

// Bound movement into parent bounds

float halfx = CGRectGetMidX(self.bounds);

newcenter.x = MAX(halfx, newcenter.x);

newcenter.x = MIN(self.superview.bounds.size.width - halfx, newcenter.x);

float halfy = CGRectGetMidY(self.bounds);

newcenter.y = MAX(halfy, newcenter.y);

newcenter.y = MIN(self.superview.bounds.size.height - halfy, newcenter.y);

// Set new location

self.center = newcenter;

}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event

{

NSLog(@"touchesEnded");

UITouch *touch = [touches anyObject];

UIScrollView *parentView = (UIScrollView *)[[[touch view] superview]superview];

parentView.scrollEnabled=YES;

}

问题分析:

最后一段一段检查,应该是parentView.scrollEnabled=NO;这句有问题。

可能是iOS的一个Bug。

问题解决:

在另一台Mac上做了一个Demo,一切OK。细细检查,唯一不同就是SDK版本不一样。出问题的那台是4.1,而做Demo一切OK的那台是4.2.1。把出问题的代码copy给4.2.1,一切安逸了。

不同iOS SDK对缺少文件后缀名图片的调用支持不同

问题描述
今天做AD杂志(iPad)特色点功能,一段相同代码转移到另一台机器,执行结果却不一样。

问题分析
代码、项目检查后完全一样,执行效果却不同,也没有报错。
因为结果是Button图片没有显示,所以一步一步检查,搜索到UIImage在转移后没有图片信息,相关代码如下:

#define PHOTO_NAME @"point"

[UIImage imageNamed:PHOTO_NAME];

以上代码实现了读入项目中point.png图片文件。

问题解决
图片后缀没有给全,改为:

#define PHOTO_NAME @"point.png"

图片出现了,问题解决了。

事后分析,估计是不同SDK对代码的支持不同。所以养成编程好习惯能省许多事情和时间。

PS:
转移前SDK:4.2.1
转移后SDK:4.1

Xcode设置代码提示的左花括号换行单独成行

Xcode代码提示生成源代码程序块默认格式如下,注意左花括号的位置:

if ( condition ) {
do ...
}

因为以前的使用习惯,我想让自动生成的左右花括号都单独成行,变成下面的样子:

if ( condition )
{
do ...
}

在Terminal里面,运行下面命令,然后重启Xcode:

defaults write com.apple.Xcode XCCodeSenseFormattingOptions -dict BlockSeparator "\n"

这个命令修改了~/Library/Preferences/com.apple.Xcode.plist,这是Xcode的配置文件

NSDictionary读plist文件顺序问题

问题描述
这些天在做AD,NSDictionar读取出来的顺序不是plist文件中的顺序。

问题分析
试了各种库和方法,无效,网上搜了一些不算解决办法的方法 。

问题解决
(1) Keep an array of keys along with the dictionary. Then loop through the array and use the keys to get the values. (You'll have to add your own checks to keep the same key from appearing in the array twice.)
1,简单说来就是,把nsdictionary的所有key组成的nsarray按自己的要求排序,然后根据这个key组成的array来获取对应的value的array。key的array不要扔掉,每次要按顺序获取值的时候都需要它。

(2)You could keep an array of custom objects, one custom object for each pair (give the object .key and .value properites) . That's a very object-oriented way, but you lose the ability to easily find the value for a key (you have to loop through the array.)
2,不直接用nsdictionary,而是用一个nsarray,里面每个object都是一个只有一对key-value的nsdictionary。这个方法的缺点是,找某个value或者key会变得很麻烦,需要遍历。

(3)You could keep two arrays of strings, one for keys and one for values.
to find a value for a key, you just use
keyIndex = [myKeys indexOfObject: keyIWant];
keyValue = [myValues objectAtIndex: keyIndex];
3,不用nsdictionary,而是用两个对应的nsarray。相互调用,分别做key和value。

Icon for iOS

App Store Icon

  • 512x512 (scaled down to 175x175 for display in the store)

Application Icon

  • 114x114 (iPhone 4)
  • 57x57 (older iPhones)
  • 72x72 (iPad)

Spotlight Search Results and Settings Icon

  • 58x58 (iPhone 4)
  • 50x50 (Spotlight results for iPad)
  • 29x29 (settings for iPad and older iPhones)

Document Icon

This is a new icon type in iOS 4. It’s used if your app creates a custom document type. The iPad uses the document icon in two different sizes.

  • 320x320 (iPad)
  • 64x64 (iPad)
  • 44x58 (iPhone 4)
  • 22x29 (older iPhones)