我曾經在一個.h文件中定義的管理對象:對象屬性沒有得到傳遞給委託
@interface MyItem : NSManagedObject {
NSString *itemName;
NSInteger itemType;
}
@property (nonatomic, retain) NSString *itemName;
@property NSInteger itemType;
@end
後來才知道有一個UIViewController,它有一個協議定義:
@protocol uiViewControllerDelegate <NSObject>
- (void) controllerIsDone:(MyItem *) myItem;
@end
通常情況下,在地方執行uiViewControler I類調用此協議:
NSLog(@"Self item has its properties %@ and %i",
self.myItem.itemName, self.myItem.itemName);
[[self delegate] controllerIsDone:self.myItem];
我有一個tableViewController是這個uiViewController的委託。
而且我有一個tableViewController
@interface tableViewController : UITableViewController <uiViewControllerDelegate>
這tableViewController實現協議方法:
- (void) controllerIsDone:(MyItem *) myItem {
NSLog("This is what I received %@ and %i", myItem.itemName, myItem.itemType);
}
能否請你告訴我,爲什麼在控制檯中我得到這個:
Self item has its properties SampleName and 1
This is what I received and 0
也就是說,儘管我將uiViewController的self.item傳遞給tableViewCon troller,它不具有它的所有屬性。爲什麼?我應該如何傳遞所有myItem對象,這樣我才能使用在uiViewController的myItem屬性中設置的屬性?
什麼奇怪的是,該指針停留:0x4d46720。 – Mantvydas
嗯。在打電話之前,'controllerIsDone',儘量保留'self.myItem'只是踢:'[self.myItem保留]' –
難道現在......沒有幫助。 – Mantvydas