黑马程序员技术交流社区

标题: protocol程序设计 [打印本页]

作者: Storm_    时间: 2015-11-12 10:48
标题: protocol程序设计
#import <Foundation/Foundation.h>
@class Student;

@protocol findHouseProtocol <NSObject>
-(void)findHouse:(Student*)stu;
@end
#import <Foundation/Foundation.h>
#import "findHouseProtocol.h"

@interface LinkHouse : NSObject<findHouseProtocol>


@end
#import "LinkHouse.h"

@implementation LinkHouse
-(void)findHouse:(Student *)stu{
    NSLog(@"帮%@找房子",stu);
}
@end

#import <Foundation/Foundation.h>
#import "findHouseProtocol.h"

@interface Student : NSObject
@property(nonatomic,strong)id<findHouseProtocol>delegate;
-(void)needHouse;
@end

#import "Student.h"

@implementation Student
-(void)needHouse{
    NSLog(@"需要房子");
    [self.delegate findHouse:self];
}
@end

#import <Foundation/Foundation.h>
#import "Student.h"
#import "LinkHouse.h"

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        Student *s = [Student new];
        LinkHouse *lk=[LinkHouse new];
        
        s.delegate = lk;
        [s needHouse];
        
        
    }
    return 0;
}





欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2