Я пытаюсь поместить UITableView в UIView. UIView также будет содержать некоторые другие вещи, поэтому я хочу захотеть определить часть UIView, которая будет использоваться UITableView. Чтение на этом и других сайтах, я использую «UIViewController» и делегаты ».Как поместить UITableView в UIView
Мои вопросы:
Почему я не вижу UITable с ниже код?
Почему я вижу UITable, когда я меняю в InformatieSectieViewController.h
@interface InformatieSectieViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>
в
@interface InformatieSectieViewController : UIViewTableController <UITableViewDataSource, UITableViewDelegate>
(UIViewController до УИ Таблица ViewController)? (Этот UITable затем обрабатывает весь UIView).
Как правильно получить UITableView в UIView.
Что меня также удивляет; когда я удалить < UITableViewDataSource, UITableViewDelegate> часть из @interface InformatieSectieViewController: UIViewController < 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
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 :
В formatieSectieViewController.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. См. [Создание пользовательского представления] (http://developer.apple.com/library/ios/documentation/WindowsViews/Conceptual/ViewPG_iPhoneOS/CreatingViews/CreatingViews.html#//apple_ref/doc/uid/TP40009503-CH5-SW23). в Руководстве по программированию _View. Или существует ли какое-то другое соображение, которое не было разделено с нами? – Rob