Jon*_*sen 2 xcode uitableview ipad ios
我一直在互联网上搜索所有的帮助,但是我手头的问题几乎没有解决方案.我试图获得喘息的项目有点独特(UI并不完全遵循典型的规范).
当前的发展环境:
下面是我想要完成的图表 - 所有这些都在UIView控制器中:

我确信经验丰富的开发人员完全了解我的问题,或者即将问我的问题.我知道静态UITableView需要在tableview控制器中,但我需要同时显示两个UItableView,这意味着它必须在UIView中.
我可以通过IB使界面看起来像我需要它,但是当我尝试编译和构建时,我收到的错误要求UITableView在UITableViewController而不是UIView控制器中.我看过许多使用主 - 细节布局的例子,但唯一的规定是这个UITableview需要在这个视图中100%显示.
所以基本上,我要求方向......但代码示例也从未受到伤害!谢谢100x的结束!
-Jonathan
UITableViewController只是一个专门UIViewController设计用于显示全屏幕UITableView的专业.它(相当)等同于使用UITableViewController子类或UIViewController <UITableViewDataSource, UITableViewDelegate>子类来管理tableview.
因此,即使UITableViewController有一些更spiecialized行为(自动创建的UITableView如果不存在的话,会自动滚动它来显示键盘,将自身设置为delegate和dataSource独特的UITableView它管理等),你可以使用一个标准UIViewController来管理UITableView和是dataSource填补它.
这甚至是一种管理没有全屏的桌面视图的方法(因为UITableViewController期望它的view属性直接是UITableView它管理的,而不是它的主视图的子视图或其他什么,因此期望它UITableView采取整个屏幕,与使用相反一个UIViewController具有UITableView作为其自定义大小的子类的view)
所以你的情况,你可以有一个UIViewController具有两个IBOutlets,每个tableView,而唯一UIViewController可以是dataSource(和delegate)的两个的UITableViews.那不是问题.请小心,然后在数据源方法中区分是否要返回第一个或第二个数据,以便UITableView每次都提供正确的表.
@interface MyViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, retain) IBOutlet UITableView* masterTableView;
@property (nonatomic, retain) IBOutlet UITableView* detailsTableView;
@end
@implementation MyViewController
@synthesize masterTableView = _masterTableView;
@synthesize detailsTableView = _detailsTableView;
// Proper memory mgmt not shown here:
// - don't forget to set self.masterTableView and self.detailsTableView to nil in viewDidUnload
// - and to release _masterTableView and _detailsTableView in your dealloc method
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
UITableViewCell* cell;
if (tableView == self.masterTableView)
{
static NSString* kMasterCellIdentifier = @"MasterCell";
cell = [tableView dequeueReusableCellWithIdentifier:kMasterCellIdentifier];
if (!cell)
{
cell = [[[UITableViewCell alloc] initWithReuseIdentiier:kMasterCellidentifier] autorelease];
// do some configuration common to all your master cells
}
// configure the rest of your cell for each property that is different from one cell to another
}
else if (tableView == self.detailsTableView)
{
// Do exactly the same principle, but for the cells of your "details" TableView
}
return cell;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2258 次 |
| 最近记录: |