Objective c 切换视图时,选项卡栏将消失。为什么?
全部 我正在用两个视图(ScrollView和TableView)制作应用程序选项卡 启动应用程序时,会出现TabBar按钮,可以更改两个视图 我在TableView中编程了按钮来改变ScrollView,视图也改变了。 但TabBar正在消失 有人,请帮帮我!给我个建议 应用程序映像: 项目视图控制器(TableView) 第二视图控制器(滚动视图)Objective c 切换视图时,选项卡栏将消失。为什么?,objective-c,ios,xcode,Objective C,Ios,Xcode,全部 我正在用两个视图(ScrollView和TableView)制作应用程序选项卡 启动应用程序时,会出现TabBar按钮,可以更改两个视图 我在TableView中编程了按钮来改变ScrollView,视图也改变了。 但TabBar正在消失 有人,请帮帮我!给我个建议 应用程序映像: 项目视图控制器(TableView) 第二视图控制器(滚动视图) #导入“SecondViewController.h” @第二视图控制器的实现 -(无效)未收到记忆警告 { //如果视图没有supervie
#导入“SecondViewController.h”
@第二视图控制器的实现
-(无效)未收到记忆警告
{
//如果视图没有superview,则释放该视图。
[超级记忆警告];
//释放所有未使用的缓存数据、图像等。
}
#pragma标记-视图生命周期
-(void)页面加载:(UIScrollView*)滚动视图{
currentPage=scrollView.contentOffset.x/scrollView.bounds.size.width;
int pageWidth=self.view.frame.size.width;
int pageHeight=self.view.frame.size.height;
prevPage.frame=CGRectMake(
页面宽度*(当前页面-1),
0,
页面宽度,
页高
);
如果(当前页面>0){
[prevPage setImage:[NSString stringWithFormat:@“%d”,当前页面-1)%kPageNum];
prevPage.hidden=否;
}否则{
prevPage.hidden=是;
}
currPage.frame=CGRectMake(
页面宽度*当前页面,
0,
页面宽度,
页高
);
[当前页面设置图像:[NSString stringWithFormat:@“%d”,当前页面%kPageNum]];
currPage.hidden=否;
nextPage.frame=CGRectMake(
页面宽度*(当前页面+1),
0,
页面宽度,
页高
);
如果(当前页面<(kPageNum-1)){
[nextPage setImage:[NSString stringWithFormat:@“%d”,(当前页面+1)%kPageNum];
nextPage.hidden=否;
}否则{
nextPage.hidden=是;
}
}
//实现viewDidLoad以在加载视图(通常从nib)后执行附加设置。
-(无效)viewDidLoad
{
[超级视图下载];
UIScrollView*scrollView=[[UIScrollView alloc]init];
scrollView.frame=self.view.bounds;
scrollView.contentSize=CGSizeMake(self.view.frame.size.width*kPageNum,self.view.frame.size.height);
scrollView.PaginEnabled=是;
[self.view addSubview:scrollView];
scrollView.delegate=self;
prevPage=[[PageView alloc]initWithFrame:self.view.bounds];
[滚动视图添加子视图:上一页];
currPage=[[PageView alloc]initWithFrame:self.view.bounds];
[滚动视图添加子视图:当前页面];
nextPage=[[PageView alloc]initWithFrame:self.view.bounds];
[滚动视图添加子视图:下一页];
[自动页面加载:滚动视图];
}
-(无效)scrollViewDidScroll:(UIScrollView*)scrollView{
CGFloat position=scrollView.contentOffset.x/scrollView.bounds.size.width;
CGFloat delta=位置-(CGFloat)当前页面;
如果(晶圆厂(δ)>=1.0f){
[自动页面加载:滚动视图];
}
}
-(无效)视图卸载
{
[超级视频下载];
//释放主视图的所有保留子视图。
//例如,self.myOutlet=nil;
}
-(布尔)应自动旋转指针面定向:(UIInterfaceOrientation)interfaceOrientation
{
//对于支持的方向返回YES
返回(interfaceOrientation==UIInterfaceOrientationGraphic);
}
@结束
您将其显示为模式视图。如果我理解您的问题,您只需要在uitabar
中切换所选项目。您可以这样做:
self.tabBarController.selectedIndex = index;
其中index是一个整数,表示要切换到的UIViewController
的索引。在您的情况下,看起来索引应该是0
#import "SecondViewController.h"
@implementation SecondViewController
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
-(void)pageLoad:(UIScrollView *)scrollView {
currentPage = scrollView.contentOffset.x / scrollView.bounds.size.width;
int pageWidth = self.view.frame.size.width;
int pageHeight = self.view.frame.size.height;
prevPage.frame = CGRectMake(
pageWidth * (currentPage - 1),
0,
pageWidth,
pageHeight
);
if (currentPage > 0) {
[prevPage setImage:[NSString stringWithFormat:@"%d", (currentPage - 1) % kPageNum]];
prevPage.hidden = NO;
} else {
prevPage.hidden = YES;
}
currPage.frame = CGRectMake(
pageWidth * currentPage,
0,
pageWidth,
pageHeight
);
[currPage setImage:[NSString stringWithFormat:@"%d", currentPage % kPageNum]];
currPage.hidden = NO;
nextPage.frame = CGRectMake(
pageWidth * (currentPage + 1),
0,
pageWidth,
pageHeight
);
if (currentPage < (kPageNum - 1)) {
[nextPage setImage:[NSString stringWithFormat:@"%d", (currentPage + 1) % kPageNum]];
nextPage.hidden = NO;
} else {
nextPage.hidden = YES;
}
}
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
[super viewDidLoad];
UIScrollView *scrollView = [[UIScrollView alloc] init];
scrollView.frame = self.view.bounds;
scrollView.contentSize = CGSizeMake(self.view.frame.size.width * kPageNum, self.view.frame.size.height);
scrollView.pagingEnabled = YES;
[self.view addSubview:scrollView];
scrollView.delegate = self;
prevPage = [[PageView alloc] initWithFrame:self.view.bounds];
[scrollView addSubview:prevPage];
currPage = [[PageView alloc] initWithFrame:self.view.bounds];
[scrollView addSubview:currPage];
nextPage = [[PageView alloc] initWithFrame:self.view.bounds];
[scrollView addSubview:nextPage];
[self pageLoad:scrollView];
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
CGFloat position = scrollView.contentOffset.x / scrollView.bounds.size.width;
CGFloat delta = position - (CGFloat)currentPage;
if (fabs(delta) >= 1.0f) {
[self pageLoad:scrollView];
}
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end
self.tabBarController.selectedIndex = index;