使用UITableView封装类似于UIAlertView控件

作者: flowerflower | 来源:发表于2016-12-12 16:51 被阅读1228次

    先上图,再墨迹。。。

    自定义UITableView.gif

    主要作用:

    封装的主要目的就是为了方便调用,如果两处或多处地方使用到了该种展现形式,应该封装起来,而不是把这里这里的内容复制到那里去,这样不仅对自己的技术没有提高,反而会出现很多冗余的代码段。

    使用方法:

    1.直接将AlertViewTable拖入项目中,其次导入头文件"HHAlertTabViewController.h",进行初始化
    2.初始化时将展现的内容通过数组传入即可。

    - (void)viewDidLoad {
        [super viewDidLoad];
        __block NSString *text = nil;
         NSArray *arr= @[@"123",@"456",@"789",@"666",@"8888",@"333",@"花花同学"];
        
        HHAlertTabViewController *alert =[[HHAlertTabViewController alloc]
    alertinitWithTitle:@"提示" dataSoreArr:arr setupAlertCellHandler:
    ^(AlertCell *cell, NSIndexPath *indexPath) {
            text = cell.nameLabel.text;
            NSLog(@"%@",cell.nameLabel.text);
        } cancelOnOnlick:^(UIButton *cancenbtn) {
            if(text==nil){
                [self message:@"请选择其中一项"];
                return ;
            }
            [self message:[NSString stringWithFormat:@"取消--%@",text]];
            
        } finishOnClick:^(UIButton *finishbtn) {
            
            if(text==nil){
                [self message:@"请选择其中一项"];
                return ;   
            }
        [self message:[NSString stringWithFormat:@"完成--%@",text]];
        }];
        
        [self.view addSubview: alert.view];
        [self addChildViewController:alert];
    }
    -(void)message:(NSString *)message{
      UIAlertView *alert =[[UIAlertView alloc]initWithTitle:nil 
                                                    message:message
                                       delegate:nil cancelButtonTitle:nil
                              otherButtonTitles:@"OK", nil];
        [alert show];
    }
    
    
    
    
    
    

    相关文章

      网友评论

        本文标题:使用UITableView封装类似于UIAlertView控件

        本文链接:https://www.haomeiwen.com/subject/ckwmmttx.html