objective-c - 一些 iPhone 菜鸟问题

标签 objective-c iphone cocoa

  1. 为什么我应该在方法中将局部变量声明为“静态”? 喜欢:static NSString *cellIdentifier = @"Cell"; 是性能优势吗? (我知道“静态”的作用;在 C 上下文中)

  2. 这个语法是什么意思? [someObj release], someObj = nil; 两个声明? 为什么我要再次分配nil? ‘释放’还不够吗? 我应该对我分配/拥有的所有对象执行此操作吗?或者只是为了查看对象?

  3. 为什么每个人都复制 NSString,但保留其他对象(在属性声明中)? 是的,NSStrings 可以改变,但是其他对象也可以改变,对吧? 那么为什么只对 NSString 进行“复制”,而不是对所有 NSString 进行“复制”呢? 这只是一个防御惯例吗?

  4. 我不应该释放常量 NSString 吗?就像这里:NSString *CellIdentifier = @"Cell"; 为什么不?编译器会为我分配/释放它吗?

  5. 在一些教程应用程序中,我观察到了这些(使用 IB 构建): 属性(IBOutlet,具有相同的 ivar 名称):window, someLabel, someTextField, etc etc... 在dealloc方法中,虽然window伊瓦尔被释放,其他人则没有。 我的问题是:为什么?我不应该也释放其他 ivars(labels, textField) 吗?为什么不呢?

  6. 假设,我有 3 个级联下拉列表。 我的意思是,根据第一个列表中选择的内容,填充第二个列表 并根据第二个列表中选择的内容填充第三个列表。 哪些 UI 组件最能体现这一点? iPhone UI 中的下拉列表是如何呈现的? 带有 UIPicker 的表格 View ?我什么时候应该更新第二、第三列表? 或者只有三个具有触摸事件的标签?

  7. 你能给我一些关于 Core-Data 的很好的示例教程吗? (不仅仅是简单的数据获取和存储在具有1/2关系的2/3表上)

  8. 我如何知道我的应用是否存在内存泄漏?有什么工具吗?

最佳答案

Why should I declare local variables as 'static' inside a method? Like: static NSString *cellIdentifier = @"Cell"; Is it a performance advantage? (I know what 'static' does; in C context)

Objective-C 中的静态与普通 C 中的静态完全相同。

What does this syntax mean?[someObj release], someObj = nil; Two statements? Why should I assign nil again? Is not 'release' enough? Should I do it for all objects I allocate/own? Or for just view objects?

这取决于上下文。它阻止了过度释放对象的任何机会,因为后续释放消息将被发送到 nil。

Why does everyone copy NSString, but retains other objects (in property declaration)? Yes, NSStrings can be changed, but other objects can be changed also, right? Then why 'copy' for just NSString, not for all? Is it just a defensive convention?

NSStrings 无法更改,但 NSMutableStrings(子类)可以。是的,这是一个防御性 session 。

Shouldn't I release constant NSString? Like here:NSString *CellIdentifier = @"Cell"; Why not? Does the compiler allocate/deallocate it for me?

阅读Cocoa Memory Management Rules 。你是通过alloc、copy还是new获取常量字符串的吗?不,你没有。因此,除非先保留它,否则不要释放它。保留常量字符串没有什么坏处。

In some tutorial application I observed these (Built with IB): Properties(IBOutlet, with same ivar name): window, someLabel, someTextField, etc etc... In the dealloc method, although the window ivar was released, others were not. My question is: WHY? Shouldn't I release other ivars(labels, textField) as well? Why not?

同样,内存管理指南会有所帮助。如果对象保留了 ivar(或使用 alloc、copy 等创建它),则需要释放它。

Say, I have 3 cascaded drop-down lists. I mean, based on what is selected on the first list, 2nd list is populated and based on what is selected on the second list, 3rd list is populated. What UI components can reflect this best? How is drop-down list presented in iPhone UI? Tableview with UIPicker? When should I update the 2nd, 3rd list? Or just three labels which have touch events?

通过。我不在 iPhone 上进行 UI 编程。

Can you give me some good example tutorials about Core-Data? (Not just simple data fetching and storing on 2/3 tables with 1/2 relationship)

Apple's Core Data Programming docs是一个很好的起点。

How can I know whether my app is leaking memory? Any tools?

尝试http://developer.apple.com/iphone/library/documentation/Performance/Conceptual/ManagingMemory/Articles/FindingLeaks.html

关于objective-c - 一些 iPhone 菜鸟问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2802201/

相关文章:

ios - pod WEPopover 弹出菜单未显示为 currentTopViewcontroller。相反,它会转到 currentTopviewController View 层次结构的后面

objective-c - 哪些问题可能导致将 nib 文件的所有者设置为 nil?

iphone - Mac 上的 Xcode 4 Organizer,如何在没有 Xcode 的情况下运行?

swift - 更改为等宽数字字体后,Cocoa NSTextField 文本在 View 中被截断

使用 xCode 3.2.4 进行 iPhone 开发

xcode - CalEvent 开始日期和结束日期与 iCal 和我的应用程序的差异

iphone - 一个 TableView 中有许多不同的 UITableViewCells

ios - 如何插入与另一个相关的核心数据记录?

ios - 应用程序 ID 和 bundle ID 有什么区别? Xcode 项目中的应用程序 ID 在哪里?

iphone - 是否有任何通用语言可以为 iphone、blackberry、windows mobile 和 android 开发相同的应用程序?