使用UITableView封裝類似于UIAlertView控件

先上圖,再墨跡。。。

自定義UITableView.gif

主要作用:

封裝的主要目的就是為了方便調(diào)用,如果兩處或多處地方使用到了該種展現(xiàn)形式,應(yīng)該封裝起來,而不是把這里這里的內(nèi)容復(fù)制到那里去,這樣不僅對自己的技術(shù)沒有提高,反而會出現(xiàn)很多冗余的代碼段。

使用方法:

1.直接將AlertViewTable拖入項目中,其次導(dǎo)入頭文件"HHAlertTabViewController.h",進(jìn)行初始化
2.初始化時將展現(xiàn)的內(nèi)容通過數(shù)組傳入即可。

- (void)viewDidLoad {
    [super viewDidLoad];
    __block NSString *text = nil;
     NSArray *arr= @[@"123",@"456",@"789",@"666",@"8888",@"333",@"花花同學(xué)"];
    
    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];
}





最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容