嗨即時嘗試設置屬性在另一個viewcontroller屬於masterviewcontoller,但它不會步入設置方法。我已經用Masterviewcontroller完成了Detailviewcontroller的工作,它工作正常。現在我複製該代碼並嘗試對masterviewcontroller執行與名爲AddNoteViewController的控制器相同的操作。相同的代碼,但它不會進入設置方法。 我有importet兩個類相同 謝謝你的幫助!設置屬性在另一個視圖控制器
調試這個作品
步驟1 masterviewController.m
//MasterViewController.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSDate *object = _objects[indexPath.row];
NSDate *kundnr = _kundnr[indexPath.row];
self.detailViewController.detailItem = object;
self.detailViewController.detailIdentity = kundnr;
self.addNoteViewController.AddNoteFtgnr = kundnr;
}
第二步DetailViewController.h
//DetailViewController.h
@property (strong, nonatomic) id detailItem;
@property (strong, nonatomic) id detailIdentity;
步驟3 DetailViewController.m
//DetailViewController.m
- (void)setDetailItem:(id)newDetailItem
{
if (_detailItem != newDetailItem) {
_detailItem = newDetailItem;
// Update the view.
[self configureView];
}
if (self.masterPopoverController != nil) {
[self.masterPopoverController dismissPopoverAnimated:YES];
}
}
- (void)setDetailIdentity:(id)newDetailItentity
{
if (_detailIdentity != newDetailItentity) {
_detailIdentity = newDetailItentity;
// Update the view.
[self configureView];
}
if (self.masterPopoverController != nil) {
[self.masterPopoverController dismissPopoverAnimated:YES];
}
}
現在不工作
步驟1 masterviewController.m 的AddNoteviewController(這是確定我認爲)
//MasterViewController.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSDate *object = _objects[indexPath.row];
NSDate *kundnr = _kundnr[indexPath.row];
self.detailViewController.detailItem = object;
self.detailViewController.detailIdentity = kundnr;
self.addNoteViewController.AddNoteFtgnr = kundnr;
}
步驟2 AddNoteViewController.h (這是確定我認爲)
//AddNoteViewController.h
@interface AddNoteViewController : UIViewController
@property (strong, nonatomic) id AddNoteFtgnr;
@end
第3步AddNoteViewController.m (這是錯誤的是它不踩在這裏的話)
//AddNoteViewController.m
-(void)setAddNoteFtgnr:(id)AddNoteFtgnr
{
//Code that sets the property
}
你是否在'masterviewController'中的任何位置初始化'addNoteViewController'? – Akhilrajtr
我做了一個#import in .m和.h我做了類AddViewController;和一個屬性非常相似,我爲detailview –