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