1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > IOS设置导航栏返回按钮 并添加事件返回主页面

IOS设置导航栏返回按钮 并添加事件返回主页面

时间:2023-03-21 22:57:57

相关推荐

IOS设置导航栏返回按钮 并添加事件返回主页面

IOS设置导航栏返回按钮,并添加事件返回主页面

前提是已经push了一个viewController了。才能使用。

XXXTableViewController 里面书写- (void)viewDidLoad {[super viewDidLoad];self.navigationItem.title = @"设置";UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"NavChevron"] style:UIBarButtonItemStylePlain target:self action:@selector(click)];self.navigationItem.leftBarButtonItem = item;}-(void)click{[self.navigationController popViewControllerAnimated:YES];}

对于UITableViewController,默认创建出来的是平板样式,即Plain样式,如果想要alloc init成Group组样式。需要重写init方法。其他地方调用的时候,强制使得它变成Group组的样式。

- (instancetype)init{self = [super init];if (self) {self.tableView = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStyleGrouped];}return self;}

别人再调的时候,默认先走一下init,发现里面有东西,会执行设置样式。当然上述讲的是纯代码方法创建UITableVIewController的为组样式,也适用于storyboard开发。

使用pop方法,返回上控制器。pop 在js中数组翻译成删除。在英文解释砰的一声。

var arr1 = [“one”,“two”,“three”]

arr1 = arr1.pop() //console.log(arr1) ,输出[“one”,“two”] 删除最后一个元素

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。