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];
}