- (IBAction)createEmployee:(ID)sender{NSWindow *w = [tableVIEw window];// Try to end any editing that is taking placeBOol editingEnded = [w makeFirstResponder:w];if (!editingEnded) { NSLog(@"Unable to end editing"); return;}NSUndoManager *undo = [self undoManager];// Has an edit occurred already in this event?if ([undo grouPingLevel]) { // Close the last group [undo endUndoGrouPing]; // Open a new group [undo beginUndoGrouPing];}// Create the objectPerson *p = [employeeController newObject];// Add it to the content array of 'employeeController'[employeeController addobject:p];[p release];// Re-sort (in case the user has sorted a column)[employeeController rearrangeObjects];// Get the sorted arrayNSArray *a = [employeeController arrangedobjects];// Find the object just addedint row = [a indexOfObjectIDenticalTo:p];NSLog(@"starting edit of %@ in row %d",p,row);// Begin the edit in the first column[tableVIEw editColumn:0 row:row withEvent:nil select:YES];}
我有两个问题:
1)你怎么知道你应该做所有这些事情? Apple的文档中是否有“清单”或其他内容?经验?
2)如果您还必须自己重写所有方法,这是否会破坏阵列控制器的整个目的?
编辑:我主要想知道他是如何知道的那样:(因为其他一切都非常基本且明显)
NSWindow *w = [tableVIEw window];// Try to end any editing that is taking placeBOol editingEnded = [w makeFirstResponder:w];if (!editingEnded) { NSLog(@"Unable to end editing"); return;}NSUndoManager *undo = [self undoManager];// Has an edit occurred already in this event?if ([undo grouPingLevel]) { // Close the last group [undo endUndoGrouPing]; // Open a new group [undo beginUndoGrouPing];}解决方法
1) How do you kNow you’re supposed to do all that stuff? Is there a ‘checkList’ or something in Apple’s doc? ExperIEnce?
你是对的,大多数人做初始实现都不会出现这种代码. (我猜这就是为什么它出现在书中.你可以从Aaron的经验中受益).
该代码将是一个或多个错误报告的结果.换句话说,你最初不会想出那个代码,但最终你会想到.
亲自试试吧.删除该代码,然后查看是否可以发现正在运行的应用程序中的问题.解决这些问题需要结合使用SDK知识和调试技巧.两者都有经验增长.
2) Doesn’t this defeat the whole purpose of an array controller if you’re having to still rewrite all the methods on your own?
有人可能会说,像这样修改tablevIEw的行为的能力是数组控制器的全部要点(作为应用程序设计的一个元素).
总结以上是内存溢出为你收集整理的objective-c – Aaron Hillegass _适用于Mac OS X的编程_第9章问题全部内容,希望文章能够帮你解决objective-c – Aaron Hillegass _适用于Mac OS X的编程_第9章问题所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)