首页 > 代码库 > iOS 协议使用(二)
iOS 协议使用(二)
ShowViewController在PopViewController拿值。注意设置代理(委托)?就像,我没有委拖你替我办事,你去银行,或者去政府替我办事,人家当然不会处理你
(1)PopViewController.h
#import <UIKit/UIKit.h>
//定义协议
@protocol popNextDeleage <NSObject]]]]>
-(void)passPopReport:(NSString*)string;
@end
@interface PopViewController : UIViewController
@property(nonatomic,retain)NSObject <popNextDeleage>*popDeleage;//声明一个代理
- (IBAction)reportAction:(UIButton *)sender;
@end
//定义协议
@protocol popNextDeleage <NSObject]]]]>
-(void)passPopReport:(NSString*)string;
@end
@interface PopViewController : UIViewController
@property(nonatomic,retain)NSObject <popNextDeleage>*popDeleage;//声明一个代理
- (IBAction)reportAction:(UIButton *)sender;
@end
(2)PopViewController.m
- (IBAction)reportAction:(UIButton *)sender {
[self.popDeleage passPopReport:@"举报"];//赋值
}
[self.popDeleage passPopReport:@"举报"];//赋值
}
(3)ShowViewController.h遵守协议popNextDeleage
@interface ShowViewController : UIViewController<iCarouselDataSource,iCarouselDelegate,UIScrollViewDelegate,UITableViewDataSource,UITableViewDelegate,popNextDeleage>{
UIView *moreView;
}
UIView *moreView;
}
(4)ShowViewController.m
//实现协议(拿到值)
-(void)passPopReport:(NSString *)string{
if ([string isEqualToString:@"举报"]) {
ReportViewController *report = [[ReportViewController alloc] init];
[self.navigationController pushViewController:report animated:YES];
}
}
-(void)passPopReport:(NSString *)string{
if ([string isEqualToString:@"举报"]) {
ReportViewController *report = [[ReportViewController alloc] init];
[self.navigationController pushViewController:report animated:YES];
}
}
(5)ShowViewController.m设置deleage
-(void)pop:(id)sender{
PopViewController *pop = [[PopViewController alloc] init];
pop.popDeleage = self;//设置deleage(谁实现了delegate方法就指定给谁)
FPPopoverController *basePop = [[FPPopoverController alloc] initWithViewController:pop];
basePop.tint = FPPopoverLightGrayTint;
basePop.arrowDirection = FPPopoverArrowDirectionAny;
[basePop presentPopoverFromView:sender];
}
PopViewController *pop = [[PopViewController alloc] init];
pop.popDeleage = self;//设置deleage(谁实现了delegate方法就指定给谁)
FPPopoverController *basePop = [[FPPopoverController alloc] initWithViewController:pop];
basePop.tint = FPPopoverLightGrayTint;
basePop.arrowDirection = FPPopoverArrowDirectionAny;
[basePop presentPopoverFromView:sender];
}
iOS 协议使用(二)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。