【发布时间】:2010-03-06 17:37:27
【问题描述】:
我有一个专为 iPhone OS 2.x 设计的应用程序。
在某些时候我有这个代码
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//... previous stuff initializing the cell and the identifier
cell = [[[UITableViewCell alloc]
initWithFrame:CGRectZero
reuseIdentifier:myIdentifier] autorelease]; // A
// ... more stuff
}
但由于 initWithFrame 选择器在 3.0 中已弃用,我需要使用 respondToSelector 和 performSelector... 转换此代码...就像这样...
if ( [cell respondsToSelector:@selector(initWithFrame:)] ) { // iphone 2.0
// [cell performSelector:@selector(initWithFrame:) ... ???? what?
}
我的问题是:如果我必须传递两个参数“initWithFrame:CGRectZero”和“reuseIdentifier:myIdentifier”,如何将 A 上的调用分解为 preformSelector 调用???
编辑 - 按照 fbrereto 的建议,我这样做了
[cell performSelector:@selector(initWithFrame:reuseIdentifier:)
withObject:CGRectZero
withObject:myIdentifier];
我遇到的错误是“'performSelector:withObject:withObject'的参数2的类型不兼容。
myIdentifier 是这样声明的
static NSString *myIdentifier = @"Normal";
我已尝试将调用更改为
[cell performSelector:@selector(initWithFrame:reuseIdentifier:)
withObject:CGRectZero
withObject:[NSString stringWithString:myIdentifier]];
没有成功...
另一点是 CGRectZero 不是一个对象...
【问题讨论】:
标签: iphone cocoa iphone-sdk-3.0 ipad