我有一个简单的应用程序,有两个基本屏幕,一个UIMapView和一个UITableView。我想在底部有一个工具栏,有两个按钮和一个带有两个段的UISegmentedControl:“Map”和“Table”。 (该布局与iPhone附带的Google Maps应用类似。)当用户来回切换时,如何在呈现UIMapView(带有UIMapViewController)或UITableView(带有UITableViewController)时保留相同的工具栏分段控制?当然,我可以为两个不同视图中的每一个创建一个相同的工具栏,并分别显示它们,但有没有更好的方法?如何将UIToolbar与多个不同的UIViewControllers一起使用?
1
A
回答
0
你可以使用一个单一的视图控制器,所有的意见(UIMapView,的UITableView等)添加到您的视图,只是显示/隐藏在点击分段控制
这样一个简单的应用程序的正确意见没有太多的意见,你不应该有一个凌乱的/聚集的视图控制器文件,并可以轻松地显示/隐藏这2个视图。
也许使用动画视图之间切换之间,所以它看起来不错
2
写,管理您的2 VC的和的MKMapView和UITableView的之间的过渡响应分段控制一个UIViewController。 首先在Interface Builder中为这个新的VC设置nib:添加一个UISegementedControl和一个简单的UIView(contentView)。 接口文件包含+动作向分段控制响应UI元素和2个VC的引用:
//
// MapAndTableViewController.h
//
#import <UIKit/UIKit.h>
#import "MyMapViewController.h"
#import "MyTableViewController.h"
@interface MapAndTableViewController : UIViewController {
IBOutlet UISegmentedControl* segmentedControl;
IBOutlet UIView* contentView;
UIViewController* firstVC;
UIViewController* secondVC;
}
-(IBAction) valueChanged:(UISegmentedControl*) sender;
@end
实现:
//
// MapAndTableViewController.m
//
#import "MapAndTableViewController.h"
@implementation MapAndTableViewController
-(IBAction) valueChanged:(UISegmentedControl*) sender {
if (sender.selectedSegmentIndex == 0) {
[UIView transitionFromView:[contentView.subviews lastObject] toView:firstVC.view duration:0.5 options:UIViewAnimationOptionTransitionFlipFromLeft completion:nil];
}
if (sender.selectedSegmentIndex == 1) {
[UIView transitionFromView:[contentView.subviews lastObject] toView:secondVC.view duration:0.5 options:UIViewAnimationOptionTransitionFlipFromLeft completion:nil];
}
}
-(void)awakeFromNib {
firstVC = [[MyMapViewController alloc] initWithNibName:@"MyMapViewController" bundle:nil];
secondVC = [[MyTableViewController alloc] initWithNibName:@"MyTableViewController" bundle:nil];
}
- (void)viewDidLoad {
[super viewDidLoad];
[contentView addSubview:firstVC.view];
}
- (void)dealloc {
[firstVC release];
[secondVC release];
[super dealloc];
}
@end
在valueChanged
方法替换当前视图并为过渡创造动力。
请注意,视图firstVC.view
和secondVC.view
是在第一次访问每个VC的视图属性时创建的。
相关问题
- 1. 将UINavigationController与同一类的UIViewControllers实例一起使用,并且没有NIB
- 2. 多个UIViewControllers同时
- 3. 添加与UITextViews一起使用的键盘的第二个UIToolBar
- 4. 如何将UNNotificationContentExtension与不同的UNNotificationAction一起使用?
- 5. 将OnClickListener与多个ImageButton一起使用?
- 6. 如何将多态性与不同头文件中的类一起使用?
- 7. 如何将NinjectModule与Ninject.MVC和多个图层一起使用?
- 8. 如何将多个索引文件与Solrnet(lucene)一起使用?
- 9. 如何将GROUP_CONCAT与多个值一起使用?
- 10. 如何将Git与多个远程存储库一起使用?
- 11. 如何将MockRestServiceServer与多个URL一起使用?
- 12. 如何将Comparator与多个字段对象一起使用?
- 13. 在同一UIViewControllers使用2的NSTimer
- 14. 如何将多个形状一起移动而不使用组
- 15. 如何将TTTAttributedLabel与'@'和'#'一起使用?
- 16. 如何将SystemBarTint与PreferenceFragment一起使用
- 17. 如何将Ninject2与WCF一起使用?
- 18. 如何将RestSharp与OAuth一起使用?
- 19. 如何将C#与AIR一起使用?
- 20. 如何将SQLAlchemy与buildozer一起使用?
- 21. 如何将stubsPerConsumer与restdocs一起使用
- 22. 如何将ZINCRBY与predis一起使用
- 23. 如何将selectAll与checkedListBox一起使用..?
- 24. 如何将yaml.load_all与fileinput.input一起使用?
- 25. 如何将$ _GET与paginator一起使用?
- 26. 如何将socketRocket与socket.io一起使用?
- 27. 如何将LINQ与ServiceModel.Channels.Message一起使用
- 28. 如何将PixelFormats.IndexedX与RenderTargetBitmap一起使用?
- 29. 如何将vimpulse与autopair.el一起使用
- 30. 如何将PhoneGap与Worklight一起使用?
你的意思是MKMapView,没有UIMapView – Felix 2010-12-28 22:18:41