码迷,mamicode.com
首页 > 移动开发 > 详细

iOS 协议使用(二)

时间:2014-09-23 16:27:34      阅读:195      评论:0      收藏:0      [点我收藏+]

标签: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


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

(3)ShowViewController.h遵守协议popNextDeleage

@interface ShowViewController : UIViewController<iCarouselDataSource,iCarouselDelegate,UIScrollViewDelegate,UITableViewDataSource,UITableViewDelegate,popNextDeleage>{

    
UIView *moreView;
    
    
}


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

    
if ([string isEqualToString:@"举报"]) {
        
ReportViewController *report = [[ReportViewController allocinit];
        [
self.navigationController pushViewController:report animated:YES];
    }
}


(5)ShowViewController.m设置deleage

-(void)pop:(id)sender{

    
PopViewController *pop = [[PopViewController allocinit];
    pop.
popDeleage = self;//设置deleage(谁实现了delegate方法就指定给谁)
    
FPPopoverController *basePop = [[FPPopoverController allocinitWithViewController:pop];
    basePop.
tint = FPPopoverLightGrayTint;
    basePop.
arrowDirection = FPPopoverArrowDirectionAny;
    [basePop 
presentPopoverFromView:sender];

}





iOS 协议使用(二)

标签:ios协议   ios代理   

原文地址:http://blog.csdn.net/u010241322/article/details/39498593

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!