因为 Apple 宣布开始接受 iPad App 的 Review,而且要赶在 27 号之前,所以我着急忙慌的将之前的 iPhone App 做一下改装。本来没想这么快就开发 iPad App,所以只能借助官方的 iPad Programming Guide 来进入。
之前在小屏幕上,不断的切换 UIView,倒是很方便的,而且内存泄露也很好查。现在这些 PopoverController、RootViewController、DetailViewController 以及 SplitViewController 混在一起,之前跑得好好的代码又出现了轻微的泄露,害得改了半天。
开发 iPad App,如果不常使用 delegate 的话,就会比较麻烦了。比如你要写 PopoverView,那么如果不通过 delegate(或者用 notification,不过没必要),那么就会费很大的劲儿。感觉上,现在 iPad App 更像是在开发一个真正意义上的应用了。
在我的第一个 iPad 应用中,除了 SplitView 自己有一个 Popover 以外,我自己还有一个 Popover,当用户按下上面的按钮的时候,需要关闭 Popover 并且将更改的数据传回主程序,同时刷新 RootViewController 里面的 tableView。以前我直接将数据传给一个 UIView,然后再 Push 它就可以了,现在则需要用 delegate。下面是核心的代码,其实很简单喽:
#pragma mark -
#pragma mark 选择代理
-(IBAction)dateSelectorButtonPushed:(id)sender {
// 获取 target
DateViewController *parent = (DateViewController *)sender;
// 重新读取数据
RootViewController *rootViewController =
(RootViewController *)[[[UIApplication sharedApplication] delegate]
rootViewController];
[rootViewController setDateMonth:parent.monthNow Day:parent.dayNow];
[rootViewController readContent];
// Dismiss
[self.popoverController dismissPopoverAnimated:YES];
self.popoverController = nil;
}
总的来说,移植还是满快的,我已经提交到 iTunes Connection 去了,上传界面多了 iPad 的截图文件上传,其它倒也没看见什么大变化。现在 Waiting For Review 了。
Tags: App, Apple, delegate, iPad, iPhone, Objective-C, splitViewController
我在不少 iPhone 程序里面使用自定义的 UITableCellView,比如之前的 80’s Movie Quotes,tableView 表现得很流畅,但是在最近一个项目中,却出现了奇怪的现象。
我自定义了一个 UITableCellView,然后在代码中引用:
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"MainCell";
MainCellViewController *cell = (MainCellViewController *)
[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"MainCellView"
owner:self
options:nil];
cell = [nib objectAtIndex:0];
}
// Set up the cell...
cell.titleLabel.text = [[content objectAtIndex:indexPath.row] title];
return cell;
}
一切看起来正常,但是在滚动 tableView 的时候,却发现有很卡的感觉,开始以为是我的 Custom UITableCellView 用了太多透明的 png,后来发现不是这样。经过检查,发现问题出在 CellIdentifier 上。
我之前一直以为 CellIdentifier 只要能区分要重复使用的 UITableCellView 就可以了,在使用默认的 tableView 的时候确实表现如此,但是用在自定义 UITableCellView 的时候就不是这样了,感觉是元件没有被缓存,每次都要重新初始化似的。
后来,我为 UITableCellView 在 IB 里面指定了 Identifier,我的 tableView 滚动马上变得平滑了。
这个定义应该可以在代码中实现,不过在 IB 中定义一下还是很方便的。
这个其实很简单,之所以记录一下,是要提醒自己,不能什么都想当然了。
Tags: Cocoa, Identifier, iPad, iPhone, Objective-C, tableView, UITableCellView, UITableView, Xcode