前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >常用代码/Code

常用代码/Code

作者头像
Helloted
发布2022-06-07 13:40:31
3460
发布2022-06-07 13:40:31
举报
文章被收录于专栏:Helloted
1、Alert
代码语言:javascript
复制
- (void)showAlert{
   UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:@"确定要这样做么" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    [alertController addAction:cancelAction];
    [alertController addAction:okAction];
    [[self getCurrentViewController] presentViewController:alertController animated:NO completion:nil]; 
}    

- (UIViewController *)getCurrentViewController
{
    UIResponder *responder = self;
    while ((responder = [responder nextResponder])){
        if ([responder isKindOfClass: [UIViewController class]]){
            return (UIViewController *)responder;
        }
    }
    return nil;
}
2、GCD
代码语言:javascript
复制
dispatch_async(dispatch_get_global_queue(0,0), ^{
	//耗时操作;
	dispatch_sync(dispatch_get_main_queue(), ^{
		//回到主线程;
	});
});
3、Tableview Delegate & DataSource
代码语言:javascript
复制
- (UITableView *)historyTableView{
    if (!_historyTableView) {
        _historyTableView = [[UITableView alloc]initWithFrame:CGRectMake(achieveMargin, 0, BaseViewWidth, 50) style:UITableViewStyleGrouped];
        _historyTableView.delegate = self;
        _historyTableView.dataSource = self;
        _historyTableView.scrollEnabled = NO;
        _historyTableView.showsVerticalScrollIndicator = NO;
        _historyTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    }
    return _historyTableView;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 10;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 50;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
	UITableViewCell *cell =  [[UITableViewCell alloc]init];
	return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

}
4、UITableViewCell
代码语言:javascript
复制
+ (instancetype)cellWithTableView:(UITableView *)tableView{
    static NSString *cellID = @"HTTableViewCell";
    HTItemTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[HTItemTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    return cell;
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {

    }
    return self;
}
5、点击事件
代码语言:javascript
复制
    [ImageView setUserInteractionEnabled:YES];
    UIGestureRecognizer* ges = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(ImageViewTapped)];
    [ImageView addGestureRecognizer:ges];
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 1、Alert
  • 2、GCD
  • 3、Tableview Delegate & DataSource
  • 4、UITableViewCell
  • 5、点击事件
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档