【发布时间】:2017-04-09 02:05:52
【问题描述】:
我希望所有人都做得很好,享受愉快的编码生活。
我想在 ParentView 中使用 ChlidView 的委托。
ChatHomeViewController(父视图)
ChatHomeViewController.h
#import <UIKit/UIKit.h>
#import "ChatActionsViewController.h"
@interface ChatHomeViewController:UIViewController<UITableViewDataSource,UITableViewDelegate, ChatActionsViewControllerDelegate>
@property (weak, nonatomic) IBOutlet UITableView *tableViewChatHome;
@property (weak, nonatomic) IBOutlet UIButton *cmdBackMenu;
@property (weak, nonatomic) IBOutlet UIView *containerViewActions;
@property (weak, nonatomic) IBOutlet UIButton *cmdShowActions;
@property (weak, nonatomic) IBOutlet UIView *viewHeadin;
@end
ChatHomeViewController.m
@interface ChatHomeViewController ()
@property (strong, nonatomic) NSMutableArray *tableData;
@end
@implementation ChatHomeViewController
@synthesize tableViewChatHome;
@synthesize cmdShowActions;
@synthesize containerViewActions;
- (void)viewDidLoad {
[super viewDidLoad];
[self setNeedsStatusBarAppearanceUpdate];
[cmdShowActions addTarget:self action:@selector(displayChatActions) forControlEvents:UIControlEventTouchUpInside];
[containerViewActions setHidden:YES];
}
-(void)displayChatActions{
ChatActionsViewController *chatActions = [[ChatActionsViewController alloc] initWithNibName:@"ChatActionsViewController" bundle:nil];
chatActions.delegate = self;
[containerViewActions setHidden:NO];
}
#pragma mark - ChatActions Delegates
-(void)creatNewChat:(NSString *)newChatOrGroup{
NSLog(@"creatNewChat:(NSString *)newChatOrGroup");
[containerViewActions setHidden:YES];
}
ChatActionsViewController(ChileView)
ChatActionsViewController.h #导入
@protocol ChatActionsViewControllerDelegate <NSObject>
@optional
-(void)creatNewChat: (NSString *)newChatOrGroup;
@end
@interface ChatActionsViewController : UIViewController
@property (assign,nonatomic) id<ChatActionsViewControllerDelegate> delegate;
@property (weak, nonatomic) IBOutlet UIView *viewBG1;
@property (weak, nonatomic) IBOutlet UIView *viewBG2;
@property (weak, nonatomic) IBOutlet UIButton *cmdCreatNewGroup;
@property (weak, nonatomic) IBOutlet UIButton *cmdCreatNewChat;
- (IBAction)actionNewChat:(id)sender;
- (IBAction)actionNewGroup:(id)sender;
@end
ChatActionsViewController.m
#import "ChatActionsViewController.h"
@interface ChatActionsViewController ()
@end
@implementation ChatActionsViewController
@synthesize viewBG1, viewBG2;
@synthesize cmdCreatNewChat, cmdCreatNewGroup;
@synthesize delegate;
- (void)viewDidLoad {
[super viewDidLoad];
[[viewBG1 layer] setCornerRadius:4];
[[viewBG1 layer] setBorderColor:[UIColor lightTextColor].CGColor];
[[viewBG1 layer] setBorderWidth:1];
viewBG1.layer.masksToBounds = NO;
viewBG1.layer.shadowOffset = CGSizeMake(1, 1);
viewBG1.layer.shadowRadius = 3;
viewBG1.layer.shadowOpacity = 0.2;
[[viewBG2 layer] setCornerRadius:4];
[[viewBG2 layer] setBorderColor:[UIColor lightTextColor].CGColor];
[[viewBG2 layer] setBorderWidth:1];
viewBG2.layer.masksToBounds = NO;
viewBG2.layer.shadowOffset = CGSizeMake(1, 1);
viewBG2.layer.shadowRadius = 3;
viewBG2.layer.shadowOpacity = 0.2;
}
- (IBAction)actionNewChat:(id)sender {
NSLog(@"actionNewChat");
[[self delegate] creatNewChat:@"1"];
}
- (IBAction)actionNewGroup:(id)sender {
NSLog(@"actionNewGroup");
[[self delegate] creatNewChat:@"2"];
}
@end
我面临的问题是委托工作不正常。最初,containerView 是隐藏的。当用户单击 "+" 按钮时,containerView 变得可见。 如果我点击 New Chat 或 New Group 按钮,我希望代理工作。
请帮我运行这个委托。 提前致谢。
【问题讨论】:
标签: ios objective-c uiviewcontroller delegates uicontainerview