【发布时间】:2013-04-25 12:06:44
【问题描述】:
我正在尝试将 UITableView 放入 UIView。 UIView 也会包含一些其他的东西,所以我想定义 UIView 的一部分供 UITableView 使用。在这个网站和其他网站上阅读时,我正在使用“UIViewController”并代表“”。
我的问题是:
为什么我没有看到任何带有以下代码的 UITable?
-
为什么我在 InformatieSectieViewController.h 中更改时会看到 UITable
@interface InformatieSectieViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>到
@interface InformatieSectieViewController : UIViewTableController <UITableViewDataSource, UITableViewDelegate>(UIViewController 到 UITableViewController)? (然后这个 UITable 就占据了整个 UIView)。
如何将 UITableView 正确放入 UIView。
-
还有什么让我感到惊讶;当我从@interface InformatieSectieViewController : UIViewController 中删除 部分时,我希望行中会出现警告(在 InformatieSectieViewController.m 中):
tabView.delegate = self; tabView.dataSource = self;但我没有收到此警告。
这是我正在使用的代码:
InformieSectie.h
#import <UIKit/UIKit.h>
@interface InformatieSectie : NSObject
@property (strong, nonatomic) NSString *header;
-(UIView*)createInformatieSectie;
@end
InformatieSectie.m
#import "InformatieSectie.h"
#import "InformatieSectieViewController.h"
#import <QuartzCore/QuartzCore.h>
@implementation InformatieSectie
@synthesize header;
@synthesize footer;
-(UIView*)createInformatieSectie{
UIView * view = [[UIView alloc] initWithFrame:CGRectMake(0, 200, breedte, hoogte)];
//(add headerlabel at pos)
[view addSubview:headerLabel];
InformatieSectieViewController *svc = [[InformatieSectieViewController alloc] init];
[view addSubview:svc.view];
return view;
}
@end
这是我定义 UITableView 的第二个类:
InformatieSectieViewController.h
#import <Foundation/Foundation.h>
@interface InformatieSectieViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, retain) UITableView *tabView;
@end
InformatieSectieViewController.m
#import "InformatieSectieViewController.h"
#import <QuartzCore/QuartzCore.h>
@implementation InformatieSectieViewController
@synthesize tabView;
-(void)loadView {
tabView = [[UITableView alloc] initWithFrame:CGRectMake(100, 100, 20, 20)];
tabView.delegate = self;
tabView.dataSource = self;
tabView.layer.borderWidth = 10.0;
tabView.layer.borderColor = [UIColor yellowColor].CGColor;
self.view = tabView;
self.view.layer.backgroundColor = [UIColor magentaColor].CGColor;
[super loadView];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// (return some cell)
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// (Nothing yet)
}
@end
【问题讨论】:
-
顺便说一句,看到
InformatieSectie是NSObject的子类非常好奇。如果它的工作是创建一个UIView对象,则更常见的是让它实际上是一个UIView子类。请参阅查看编程指南中的Creating a Custom View。 或者还有其他一些尚未与我们分享的设计考虑因素?
标签: ios uitableview uiview