【发布时间】:2011-10-21 15:59:17
【问题描述】:
我在 UINavigation 环境中使用它。 我有 customClassA。它继承了 customClassB,其中一个对象是 NSMutableDictionary。
我在 viewController 中分配和初始化 customClassA,然后为了添加数据,我将新的 viewController 推入堆栈。 addNewDataViewController 发送新添加的数据,一个 customClassB 对象由它的委托返回。到目前为止一切正常。
customClassA 必须使用键(从 NSDate 创建的 NSString)将返回的对象 (customClassB) 存储到其 NSMutableDictionary 对象中。
我收到“发送到不可变对象的变异方法”错误,想不出任何解决方案。 任何帮助表示赞赏。
谢谢。
============================
interface customClassA : NSObject
{
NSDate date;
NSArray *array; // will contain only NSString objects
}
// and the rest as customary
...
#import "customClassA.h"
interface customClassB : NSObject
{
NSString *title;
NSMutableDictionary *data; // will contain values of customClassA with keys of NSString
}
// and the rest as customary
...
#import "customClassB"
#interface firstViewController : UITableViewController <SecondViewControllerDelegate>
- (void)viewDidLoad
{
self.customClassB_Object = [customClassB alloc] init];
// and the rest...
}
- (void)secondViewControllerDidSaveData:(customClassA *)aData
{
[self.customClassB_Object.data setObject:aData forKey:[NSString stringWithFormat:@"%@", aData.date]];
// update tableView
}
【问题讨论】:
-
您能否围绕问题区域发布更多代码以及如何创建 NSMutableDictionary
-
我发布了一些代码。希望对您有所帮助。
-
customClassB_Object 定义在哪里?
-
self.customClassB_Object 在头文件中定义并在 viewDidLoad 中分配、初始化。
-
你需要在 secondViewControllerDidSaveData 中做 self.customClassB_Object.data