你好,歡迎來到IOS教程網

 Ios教程網 >> IOS訊息 >> 關於IOS >> iOS 協議使用(二)

iOS 協議使用(二)

編輯:關於IOS

ShowViewController在PopViewController拿值。注意設置代理(委托)?就像,我沒有委拖你替我辦事,你去銀行,或者去政府替我辦事,人家當然不會處理你

(1)PopViewController.h
#import

//定義協議
@protocol popNextDeleage

-(void)passPopReport:(NSString*)string;

@end

@interface PopViewController : UIViewController

@property(nonatomic,retain)NSObject *popDeleage;//聲明一個代理

- (IBAction)reportAction:(UIButton *)sender;

@end

(2)PopViewController.m - (IBAction)reportAction:(UIButton *)sender {

[self.popDeleage passPopReport:@"舉報"];//賦值

}

(3)ShowViewController.h遵守協議popNextDeleage
@interface ShowViewController : UIViewController{

UIView *moreView;

}

(4)ShowViewController.m //實現協議(拿到值)
-(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];

}

  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved