UITableView を UIView に入れようとしています。UIView には他にもいくつかの要素が含まれるため、UITableView で使用される UIView の一部を定義したいと考えています。このサイトや他のサイトを読んで、「UIViewController」とデリゲート「」を使用しています。
私の質問は次のとおりです。
以下のコードで UITable が表示されないのはなぜですか?
InformatieSectieViewController.h を変更すると UITable が表示されるのはなぜですか
@interface InformatieSectieViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>
に
@interface InformatieSectieViewController : UIViewTableController <UITableViewDataSource, UITableViewDelegate>
(UIViewController から UIテーブルViewController)? (この UITable は UIView 全体を占有します)。
UITableView を UIView に正しく取得するにはどうすればよいですか。
また、私を驚かせたこと。@interface InformatieSectieViewController : UIViewController < UITableViewDataSource, UITableViewDelegate> から < UITableViewDataSource, UITableViewDelegate> 部分を削除すると、(InformatieSectieViewController.m 内の) 行に警告が表示されます。
tabView.delegate = self; tabView.dataSource = self;
しかし、私はこの警告を受けません。
私が使用しているコードは次のとおりです。
InformatieSectie.h
#import <UIKit/UIKit.h>
@interface InformatieSectie : NSObject
@property (strong, nonatomic) NSString *header;
-(UIView*)createInformatieSectie;
@end
情報Sectie.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 を定義する 2 番目のクラスです。
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