iOS 协议使用(二)

ViewController在 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


(2) PopViewController.m
- ( IBAction )reportAction:( UIButton  *)sender {
    
    [
self . popDeleage   passPopReport : @" 赋值 " ]; // 赋值
    
}

(3) ViewController.h遵守协议 popNextDeleage

@interface  ViewController :  UIViewController < popNextDeleage >{

    
UIView  *moreView;
    
    
}


(4) ShowViewController.m
// 实现协议(拿到值)
-(
void )passPopReport:( NSString  *)string{

    
if  ([string  isEqualToString : @" 赋值 " ]) {
        
ReViewController  *re = [[ ReViewController   alloc init ];
        [
self . navigationController   pushViewController :re  animated : YES ];
    }
}


(5) ViewController.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];

}





评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值