哈特中尉's Blog

不会写代码的司机不是好厨师!

objc开发UI

1.下载历史版本xcode

https://developer.apple.com/download/more

2.安装两个版本xcode

http://www.jianshu.com/p/c266b4623900

1.添加点击事件

  • storyboard添加
    1
    2
    3
    -(void) onButtonClick:(id)sender{
    [sender setHighlighted:YES];
    }
  • UIButton
    1
    2
    3
    4
    5
    [button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];

    -(void)buttonClick:(UIButton *) button{

    }
  • UIView
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    UITapGestureRecognizer *tapGesturRecognizer=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(onItemClick:)];
    [view addGestureRecognizer:tapGesturRecognizer];
    view.userInteractionEnabled = YES; // 可以理解为设置label可被点击

    -(void)onItemClick:(id)sender{
    NSInteger tag = 0;
    if([sender isKindOfClass:[UITapGestureRecognizer class]]){
    tag= ((UITapGestureRecognizer *) sender).view.tag;
    }else if([sender isKindOfClass:[UIView class]]){
    tag= ((UIView *) sender).tag;
    }
    注意:一个UITapGestureRecognizer只能对应一个View。

2.UIViewControl的打开和关闭(A->B)

  • NavigationController
    在A中打开B
    [self.navigationController pushViewController:dest animated:YES];
    在B中关闭自己(实际是关闭栈顶)
    self.navigationController popViewControllerAnimated:<#(BOOL)#>
  • UIViewControl
    在A中打开B
    presentViewController:dest animated:YES completion:^{
    1
    2
      NSLog(@"ok");
    }];
    在B中关闭自己
    [self dismissViewControllerAnimated:YES completion:nil];

参考地址:http://blog.csdn.net/u010850094/article/details/52274438

3.自定义cell上的button点击事件
  • 1.在cell里,.h写一个Block.
    1
    @property (nonatomic,copy)void(^agreeBlock)();
    1. 在cell里,.m写一个点点击事件.
      1
      2
      3
      4
      5
      - (IBAction)agreeClick:(id)sender {
      if (self.agreeBlock) {
      self.agreeBlock();
      }
      }
  • 3.在tableView中
    1
    2
    3
    4
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    cell.telephoneBlock=^(){
    NSLog(@"phonenumber is ======%@",shopmodel.phone);
    };