所以我试图使用下面显示的代码显示一个UITableView
内部UIPopoverController
vc = [[ActionsViewController alloc] init];
initWithContentViewController:vc];
actionsController = [[UIPopoverController alloc] initWithContentViewController:vc];
actionsController.delegate = self;
NSLog(@"Try to sho it ");
[actionsController presentPopoverFromBarButtonItem:(UIBarButtonItem*)sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
这是 ActionsViewController.m 的子类UITableViewController
- (void)viewDidLoad
{
[super viewDidLoad];
NSMutableArray* list = [[NSMutableArray alloc] initWithCapacity:4];
self.actionList = list;
self.clearsSelectionOnViewWillAppear = NO;
self.contentSizeForViewInPopover = CGSizeMake(320.0, 400.0);
[self.actionList addObject:@"Print as book"];
[self.actionList addObject:@"Print page"];
[self.actionList addObject:@"Save Page"];
[self.actionList addObject:@"Share"];
}
- (int)numberOfSectionsInTableView:(UITableView *)tableView
{
NSLog(@"in number of section");
return 1;
}
- (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
NSString* lab = [self.actionList objectAtIndex:indexPath.row];
NSLog(@"here in there");
cell.textLabel.text = lab;
return cell;
}
- (NSInteger)numberOfRowsInSection:(NSInteger)section
{
return [self.actionList count];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (self.delegate != nil) {
[self.delegate actionSelected:indexPath.row];
}
}
对应的.h文件
#import <UIKit/UIKit.h>
@protocol KLActionsViewControllerDelegate
- (void)actionSelected:(NSInteger)index;
@end
@interface KLActionsViewController : UITableViewController <UITableViewDataSource,UITableViewDelegate>
@property (nonatomic, retain) NSMutableArray* actionList;
@property (nonatomic, assign) id<KLActionsViewControllerDelegate> delegate;
@end
另外,我不认为这些函数cellForRowAtIndexPath
会numberOfSectionsInTableView
被调用,因为我没有看到任何控制台输出。
编辑:这就是我在弹出窗口中看到的
: