我解决了选项卡式视图控制器的问题,可以帮助一些人。
现在进入处理步骤。
答案 0 :(得分:0)
我有一个解决您问题的方法。如果使用模态显示视图,请尝试使用此代码关闭视图控制器: //夫特
self.dismissViewControllerAnimated(true, completion: {});
//目标C
[self dismissViewControllerAnimated:YES completion:nil];
在完成处理程序中执行类似这样的操作来更改选项卡栏索引:
NSInteger indexOfTabToSwitchTo = 1//Change this number according to your preference of controller
[self.presentingViewController.tabBarController setSelectedIndex:indexOfTabToSwitchTo];
/。结合在一起可能会看起来像这样
[self dismissViewControllerAnimated:YES completion:^{
NSInteger indexOfTabToSwitchTo = 1//Change this number according to your preference of controller
[self.presentingViewController.tabBarController setSelectedIndex:indexOfTabToSwitchTo];
}];
答案 1 :(得分:0)
您可以使用标签栏控制器的selectedIndex属性来解决您的问题
// Create button in `ViewDidLoad` and add to tableview.
- (void)viewDidLoad
{
[super viewDidLoad];
// *** Creat a button, calculate Y position at bottom of table, assign frame & add to tableview ***
_btnFloating = [UIButton buttonWithType:UIButtonTypeCustom];
CGFloat yPos = self.tableView.contentOffset.y + CGRectGetHeight(self.tableView.bounds) - CGRectGetHeight(_btnFloating.bounds);
[_btnFloating setFrame:CGRectMake(0, yPos, [UIScreen mainScreen].bounds.size.width, 50)];
[self.tableView addSubview:_btnFloating];
// *** Adjust Inset and scroll indicator of tableview ***
self.tableView.contentInset = UIEdgeInsetsMake(0.0f, 0.0f, CGRectGetHeight(_btnFloating.bounds), 0.0);
self.tableView.scrollIndicatorInsets = UIEdgeInsetsMake(0.0f, 0.0f, CGRectGetHeight(_btnFloating.bounds), 0.0);
// *** Add observer on tableview frame change to update floating button frame ***
[self.tableView addObserver:self
forKeyPath:@"frame"
options:0
context:NULL];
}
#pragma mark - KVO
- (void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary *)change
context:(void *)context {
if([keyPath isEqualToString:@"frame"]) {
[self adjustFloatingViewFrame];
}
}
- (void)adjustFloatingViewFrame
{
CGRect newFrame = _btnFloating.frame;
newFrame.origin.x = 0;
newFrame.origin.y = self.tableView.contentOffset.y + CGRectGetHeight(self.tableView.bounds) - CGRectGetHeight(_btnFloating.bounds);
_btnFloating.frame = newFrame;
[self.tableView bringSubviewToFront:_btnFloating];
}
#pragma mark - UIScrollViewDelegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
[self adjustFloatingViewFrame];
}
// Don't forget to remove Observer on Tableview otherwise it will lead to crash.
-(void)dealloc
{
[self.tableView removeObserver:self forKeyPath:@"frame"];
}
-
试试这个
[self.tabBarController setSelectedIndex:0];
答案 2 :(得分:0)
您可以使用此代码:
[self dismissViewControllerAnimated:YES completion:^{
[self.tabBarController setSelectedIndex:0];
}];