Ios5 感谢您的回复,我通读了教程,并对委托协议模式做了更多的阅读。我基本上明白了,但是如果你不介意的话,我需要更多的提示来应用它。我想让RootViewController符合委托协议的想法正确吗?我可以通过在RootViewController.h中创建一个委

Ios5 感谢您的回复,我通读了教程,并对委托协议模式做了更多的阅读。我基本上明白了,但是如果你不介意的话,我需要更多的提示来应用它。我想让RootViewController符合委托协议的想法正确吗?我可以通过在RootViewController.h中创建一个委,ios5,xcode4.2,storyboard,iboutlet,Ios5,Xcode4.2,Storyboard,Iboutlet,感谢您的回复,我通读了教程,并对委托协议模式做了更多的阅读。我基本上明白了,但是如果你不介意的话,我需要更多的提示来应用它。我想让RootViewController符合委托协议的想法正确吗?我可以通过在RootViewController.h中创建一个委托属性,然后在RootViewController.m中@synthesis来实现这一点吗?还是我迷糊了?谢谢你让我走上了正确的道路——最终我需要做的是回到过去,确保我正确理解了底层的MVC模式。我使用了优秀的斯坦福系列讲座(可通过iTunes


感谢您的回复,我通读了教程,并对委托协议模式做了更多的阅读。我基本上明白了,但是如果你不介意的话,我需要更多的提示来应用它。我想让RootViewController符合委托协议的想法正确吗?我可以通过在RootViewController.h中创建一个委托属性,然后在RootViewController.m中@synthesis来实现这一点吗?还是我迷糊了?谢谢你让我走上了正确的道路——最终我需要做的是回到过去,确保我正确理解了底层的MVC模式。我使用了优秀的斯坦福系列讲座(可通过iTunes U获得),现在我对正在发生的事情有了更深入的了解,而之前我只是在半了解的情况下进行黑客攻击。
//RootViewController.h
#import <UIKit/UIKit.h>

@interface RootViewController : UIViewController <UIPageViewControllerDelegate>
@property (strong, nonatomic) UIPageViewController *pageViewController;
@end


//DataViewController.h
#import <UIKit/UIKit.h>
@class RootViewController;

@interface DataViewController : UIViewController < UIWebViewDelegate > {
    IBOutlet UIWebView *webView;
}
@property (strong, nonatomic) IBOutlet RootViewController *rvc; //this one won't connect. Why?
@property (strong, nonatomic) IBOutlet UILabel *dataLabel;
@property (strong, nonatomic) id dataObject;
@end

//DataViewController.m
#import "DataViewController.h"
#import "RootViewController.h"

@implementation DataViewController

@synthesize rvc;

//...
@end
// this next statement is need to inform Select of the protocols defined in Edit
#import "EditNoteViewController.h" // STEP 1


@interface SelectNoteViewController : UITableViewController <EditNoteViewControllerDelegate> { ... // STEP 2: this says Select implements the protocol I created
...
// STEP 3: EditNoteViewController Delegate Methods - these are the methods in the protocol
- (Notes *)selectPreviousNote;
- (Notes *)selectNextNote;
// STEP 4: the protocol methods are implemented
- (Notes *)selectPreviousNote {
    if (isPreviousToSelectedNote) {
        NSIndexPath *indexPath, *previousIndexPath;
        indexPath = [self.tableView indexPathForSelectedRow];
        previousIndexPath = [NSIndexPath indexPathForRow:indexPath.row+1 inSection:0];
        // update the selected row
        self.selectedNote = [self.fetchedResultsController objectAtIndexPath:previousIndexPath];
        [self.tableView selectRowAtIndexPath:previousIndexPath animated:NO scrollPosition:UITableViewScrollPositionMiddle];
        [self setPreviousNote];
        [self setNextNote];
    } 
return selectedNote;
}

- (Notes *)selectNextNote {
    if (isNextToSelectedNote) {
        NSIndexPath *indexPath, *nextIndexPath;
        indexPath = [self.tableView indexPathForSelectedRow];
        nextIndexPath = [NSIndexPath indexPathForRow:indexPath.row-1 inSection:0];
        // update the selected row
        self.selectedNote = [self.fetchedResultsController objectAtIndexPath:nextIndexPath];
        [self.tableView selectRowAtIndexPath:nextIndexPath animated:NO scrollPosition:UITableViewScrollPositionMiddle];
        [self setPreviousNote];
        [self setNextNote];
    }
return selectedNote;
}
...
    ...
if ([[segue identifier] isEqualToString:@"editNote"])  {
    // STEP 5: this is where Edit is told that its delegate is Select
    [[segue destinationViewController] setEditNoteViewControllerDelegate:self]; // STEP 5
#import ... // put protocol after import statements
// STEP 6
@protocol EditNoteViewControllerDelegate <NSObject>

- (Notes *)selectPreviousNote;
- (Notes *)selectNextNote;

@end


@interface ...
// STEP7: Edit needs a property to tell it who the delegate is - it was set back in Select.m
@property (weak) id <EditNoteViewControllerDelegate> editNoteViewControllerDelegate; 
// STEP 8: the property is synthesized
@synthesize editNoteViewControllerDelegate;

...

// STEP 9: now when any method needs to call selectPreviousNote or selectNext Note it does it like this:
selectedNote = [self.editNoteViewControllerDelegate selectPreviousNote];
// or
selectedNote = [self.editNoteViewControllerDelegate selectNextNote];