iOS复习 获取Tabbar的item 用UIAlertController修改英雄名称并刷新表格

 Tabbar的生命周期:

  

#import "MainTabBarController.h"


@interface MainTabBarController ()


@end


@implementation MainTabBarController


- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view.


    

    // 拿到TabBar相应的item

    UITabBarItem *item1 = [self.tabBar.items objectAtIndex:1];

    item1.selectedImage = [[UIImage imageNamed:@"add_icon_people_you_might_know"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

    item1.image = [[UIImage imageNamed:@"tab_buddy_nor"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

    item1.title = @"联系人";

   

    //设置tabbar背景图片

    UIView *bgView = [[UIView alloc] initWithFrame:self.tabBar.bounds];

    bgView.backgroundColor = [UIColor blackColor];

    //    [UIColor colorWithWhite:0.1 alpha:0.6];

    [self.tabBar insertSubview:bgView atIndex:0];

    self.tabBar.opaque = YES; //设置为不透明

    

    //设置tabbar选中颜色,默认为蓝色

    self.tabBar.tintColor=[UIColor orangeColor];

//    [self.tabBar setTintColor:[UIColor colorWithRed:0.33f green:0.77f blue:1.00f alpha:1.00f]];


    //横向分界(割)线,默认为NO,显示,如不要显示,设置为YES

    [self.tabBar setClipsToBounds:YES];

    

}



#pragma mark - 修改英雄名称并刷新表格

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

    //1.获取选中行的英雄名称

    HerosModel *hero = self.dataArray[indexPath.row];

    

    //2.创建一个对话框对象

    UIAlertController *alert =[UIAlertController alertControllerWithTitle:@"英雄名称编辑" message:nil preferredStyle:UIAlertControllerStyleAlert];

    

    [alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {

        textField.text = hero.name;

    }];

    

    //创建确定按钮

    UIAlertAction *ok = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {

        hero.name = [alert.textFields objectAtIndex:0].text;

        

        //刷新全表格

//        [self.tableView reloadData];

        

        //局部刷新,刷新指定行或组

        [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];

    }];

    

    //创建取消按钮

    UIAlertAction *cancle = [UIAlertAction actionWithTitle:@"取消"style:UIAlertActionStyleCancel handler:nil];

    

    //把这两个按钮添加到提示框中

    [alert addAction:ok];

    [alert addAction:cancle];

    

    //弹出提示框

    [self presentViewController:alert animated:YES completion:nil];

}




  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值