我真的在努力将变量从一个类传递到另一个类。我在this问题中遵循了答案,并且能够成功实施第一部分(传递数据转发)。我的问题是当我到达第二部分(传递数据)时,我被挂起4)
,我需要为我的second.h文件声明一个接口。我已经在.h文件中声明了一个接口:
@interface RootViewController : UITableViewController <UISplitViewControllerDelegate>{
当我尝试宣布另一个时,我遇到了很多错误。我读到这是可能的,我只是不确定我猜的确切语法。
这是完整的.h文件
#import <UIKit/UIKit.h>
@protocol SubstitutableDetailViewController
- (void)showRootPopoverButtonItem:(UIBarButtonItem *)barButtonItem;
- (void)invalidateRootPopoverButtonItem:(UIBarButtonItem *)barButtonItem;
@end
@interface RootViewController : UITableViewController <UISplitViewControllerDelegate>{
UISplitViewController *splitViewController;
UIPopoverController *popoverController;
UIBarButtonItem *rootPopoverButtonItem;
NSMutableArray *logMessages;
}
@property (nonatomic, assign) IBOutlet UISplitViewController *splitViewController;
@property (nonatomic, retain) UIPopoverController *popoverController;
@property (nonatomic, retain) UIBarButtonItem *rootPopoverButtonItem;
@end
答案 0 :(得分:2)
要添加第二个(或第三个或第四个)界面,只需使用逗号
你说的例子?我想我可以做一个。
@interface ViewController : UIViewController <DateControllerDelegate, TimeControllerDelegate, DivisionControllerDelegate, FormControllerDelegate, MemoryControllerDelegate, UIAlertViewDelegate, UITextFieldDelegate, UIActionSheetDelegate, UITableViewDelegate, UITableViewDataSource, NSFetchedResultsControllerDelegate, MFMailComposeViewControllerDelegate> {
看起来您需要查找委托方法。以下是我能想到的最简单的解释。
Delegates
//In parent .m file:
//assign the delegate
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([segue.identifier isEqualToString:@"segueName"])
{
childController *foo = segue.destinationViewController;
foo.delegate = self;
}
}
//implement protocol method(s):
- (void) methodName:(dataType*) dataName
{
//An example of what you could do if your data was an NSDate
buttonLabel.titleLabel.text = [[date description] substringToIndex:10];
}
//In parent .h file:
//import child header
#import "ChildName.h"
//indicate conformity with protocol
@interface ParentName : UIViewController <ChildNameDelegate>
//In child .h file
//declare protocol
@protocol ChildNameDelegate
- (void) methodName:(dataType*) dataName;
@end
//declare delegate
@property (unsafe_unretained, nonatomic) id<ChildNameDelegate> delegate;
//In child .m file
//synthesize delegate
@synthesize delegate;
//use method
- (IBAction)actionName:(id)sender
{
[delegate methodName:assignedData];
}
这里有一个关于代表的好答案,可能比我的好: How do I create delegates in Objective-C?