0
A
回答
1
既然你实际上并没有创建一个新的实例(只检索一个),没有必要为此。这是足够的:
// If we don't know the exact class of the cell, type it with the common superclass of all cells
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"rssItemCell"];
0
你不能使用变量cellClass作为类型,它是一个对象。
在这种情况下,你必须使用一个id对象或UITableViewCell中。事情是这样的:
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"rssItemCell"];
或
id cell = [tableView dequeueReusableCellWithIdentifier:@"rssItemCell"];
3
因为你在运行时创建cellClass,编译器不知道它,所以它不能编译代码。
这会工作:
Class cellClass = NSClassFromString(@"CustomCell");
UITableViewCell *cell; // You could just id here as well if you wanted but you now that CustomCell is definitely a type of UITableViewCell
cell = [tableView dequeueReusableCellWithIdentifier:@"rssItemCell"];
可是,为什么你不这样做呢?
CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:@"rssItemCell"];
相关问题
- 1. NSClassFromString与objc_getClass?
- 2. 无法在Swift 4中使用NSClassFromString工作
- 3. NSClassFromString大小写不敏感Objective-C
- 4. 使用Swift文件的NSClassFromString
- 5. NSClassFromString会影响性能吗?
- 6. 目标C中的工厂方法模式:NSClassFromString()
- 7. NSClassFromString()即使在课程不可用时也会返回类
- 8. GET工作POST不工作
- 9. Laravel 5.3“工作”不工作
- 10. Web工作不工作
- 11. 延迟工作不工作
- 12. 克伦工作不工作
- 13. sidenav不工作时按钮不工作
- 14. 。不(此)不工作?
- 15. 不工作
- 16. phpwebsocket不工作
- 17. 不工作
- 18. 不工作bitmap.compress
- 19. PHAssetCreationRequest不工作
- 20. ajaxcontoltoolkit不工作
- 21. .click不工作
- 22. DSBezelActivityView不工作
- 23. Tidhttp.connectTimeout不工作!
- 24. updateExistingPivot()不工作
- 25. logging.handlers.WatchedFileHandler不工作
- 26. getenv()不工作
- 27. Dajax不工作
- 28. \ n不工作 “”
- 29. CrossFadeAlpha不工作
- 30. pickerview.reloadAllComponents()不工作
因为它不会总是CustomCell,它必须是不固定的,谢谢你的帮助,我会测试你的解决方案 – Mapedd 2010-11-16 14:01:17