0
我想在一个弹出窗口中显示一个tableViewController,像这样创建TableViewController。UITableViewController不调用委托方法
@interface ContentViewController :UITableViewController{
}
@end
@implementation ContentViewController
- (id)initWithStyle:(UITableViewStyle)style {
if ((self = [super initWithStyle:style])) {
self.contentSizeForViewInPopover = CGSizeMake(100,400);
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
return 10;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLabel.text = [NSString stringWithFormat:@"Item %d", [indexPath row]];
cell.textLabel.textColor = [UIColor whiteColor];
return cell;
}
从另一个ViewController我在popOver中调用这个tableViewController如下。
UIViewController *contentViewController = [[ContentViewController alloc] initWithStyle:UITableViewStylePlain];
self.popoverController = [[popoverClass alloc] initWithContentViewController:contentViewController] ;
self.popoverController.delegate = self;
CGRect rect = btn.frame;
[self.popoverController presentPopoverFromRect:rect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
当我和初始化语句的tableView委托方法不调用,并在酥料饼没有分配ContentViewController创建。
如何使这个委托方法调用。
你设置委托花花公子? – 2013-04-04 12:21:17
只需在'ContentViewController'的'viewDidLoad'中设置tableView的委托和数据源。 – vishy 2013-04-04 12:22:29
ContentViewController的超类是UITableViewController,因此不需要再次设置委托。用这个语句它必须调用所有的委托方法(self = [super initWithStyle:style]),任何我在viewDidLoad中编写委托但没用。 – Madhu 2013-04-04 12:27:08