gpt4 book ai didi

cocoa - 空选择器发送到 NSMutableArray 中的第一项

转载 作者:行者123 更新时间:2023-12-03 17:08:21 24 4
gpt4 key购买 nike

每当我调用此方法时:

- (IBAction)addListItem: (id)sender {  
NSString *newItemText = [inputField stringValue];
TodoItem *newItem = [[TodoItem alloc] initWithGUID:nil text:newItemText];
[newItem autorelease];
[self willChangeValueForKey: @"list"];
[list addObject: newItem];
[self didChangeValueForKey: @"list"];
[inputField setStringValue: @""];
}

第一个TodoItem实例位于 list发送一个空选择器,并且控制台打印一条错误。这种情况发生了两次,当我调用 addObject 时就不再发生了多次,或调用didChangeValueForKey多次。有什么想法可以阻止这种情况发生吗?

显示的错误消息是:
-[TodoItem <null selector>]: unrecognized selector sent to instance 0x11470b0e0

这是我在 [NSObject(NSObject) doesNotRecognizeSelector] 设置断点时的堆栈回溯方法:

#0   0x7fff87ea32fa in objc_exception_throw
#1 0x7fff86c952a0 in -[NSObject(NSObject) doesNotRecognizeSelector:]
#2 0x7fff86c0f30f in ___forwarding___
#3 0x7fff86c0b458 in __forwarding_prep_0___
#4 0x7fff831d099b in -[NSObject(_NSBinderKeyValueCodingAdditions) _invokeSelector:withArguments:onKeyPath:]
#5 0x7fff82e4b171 in -[NSArrayController _invokeMultipleSelector:withArguments:onKeyPath:atIndex:]
#6 0x7fff82e4a423 in -[NSArrayController _invokeSingleSelector:withArguments:onKeyPath:]
#7 0x7fff831d08d1 in -[NSObject(_NSBinderKeyValueCodingAdditions) _invokeSelector:withArguments:onKeyPath:]
#8 0x7fff82e5b4d0 in -[NSBinder _invokeSelector:withArguments:onKeyPath:ofObject:mode:raisesForNotApplicableKeys:]
#9 0x7fff82e57f3b in -[NSBinder invokeSelector:withArguments:forBinding:error:]
#10 0x7fff82e3a0ba in -[NSActionBinder _invokeSelector:withArguments:forBinding:]
#11 0x7fff82e39f20 in -[NSActionBinder _ performActionWithCommitEditing:didCommit:contextInfo:]
#12 0x7fff82daa259 in _NSSendCommitEditingSelector
#13 0x7fff82dabbc7 in -[NSController _controllerEditor:didCommit:contextInfo:]
#14 0x7fff86c1235c in __invoking___
#15 0x7fff86c1222d in -[NSInvocation invoke]
#16 0x7fff86c2df21 in -[NSInvocation invokeWithTarget:]
#17 0x7fff8363d500 in __NSFireDelayedPerform
#18 0x7fff86bd9a78 in __CFRunLoopRun
#19 0x7fff86bd803f in CFRunLoopRunSpecific
#20 0x7fff84c4bc4e in RunCurrentEventLoopInMode
#21 0x7fff84c4b9b1 in ReceiveNextEventCommon
#22 0x7fff84c4b90c in BlockUntilNextEventMatchingListInMode
#23 0x7fff82be8520 in _DPSNextEvent
#24 0x7fff82be7e89 in -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:]
#25 0x7fff82bada7d in -[NSApplication run]
#26 0x7fff82ba6798 in NSApplicationMain
#27 0x100001211 in main at main.m:13

最佳答案

看起来您有一个控件,其目标属性绑定(bind)到待办事项,但没有操作绑定(bind)。如果是这种情况,您应该使用常规 IB 连接来设置操作。

关于cocoa - 空选择器发送到 NSMutableArray 中的第一项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1691921/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com