gloryFlow的专栏

本博客关联网站 www.wahenzan.com

block使用的一个例子

.h
// Copyright © 2015年 1. All rights reserved.
//

import

import “BlockDemoViewController.h”

import “BlockCustomItem.h”

import “BlockCustomButton.h”

@interface BlockDemoViewController ()

@end

@implementation BlockDemoViewController

  • (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    BlockCustomItem *customItem = [[BlockCustomItem alloc] init];
    customItem.block = ^{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@”提示” delegate:self cancelButtonTitle:@”取消” otherButtonTitles:@”确定”, nil];
    [alert show];
    };

    BlockCustomButton *blockButton = [BlockCustomButton buttonWithType:UIButtonTypeCustom];
    blockButton.frame = CGRectMake(50, 100, 100, 30);
    blockButton.backgroundColor = [UIColor colorWithRed:59.0/255.0 green:249.0/255.0 blue:199.0/255.0 alpha:1.0];
    blockButton.item = customItem;
    [blockButton addTarget:self action:@selector(blockButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:blockButton];
    }

  • (void)blockButtonAction:(BlockCustomButton *)button {
    if (button.item.block) {
    button.item.block();
    }
    }

  • (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
    }

@end

.h

import

import “BlockCustomItem.h”

@interface BlockCustomButton : UIButton

@property (nonatomic, strong) BlockCustomItem *item;

@end

.m

import “BlockCustomButton.h”

@implementation BlockCustomButton

@end

.h

import

import “BlockCustomItem.h”

@implementation BlockCustomItem

  • (id)init {
    self = [super init];
    if (self) {
    self.title = @”“;
    }
    return self;
    }

@end

阅读更多
文章标签: 界面 编辑器
个人分类: iphone开发
想对作者说点什么? 我来说一句

block的一些例子

2014年12月24日 48KB 下载

没有更多推荐了,返回首页

不良信息举报

block使用的一个例子

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭