Ios 如何使用数据在popoverController中显示我的tableview

Ios 如何使用数据在popoverController中显示我的tableview,ios,Ios,现在我已经创建了一个带有tableview的popoverController,并且创建了将在tableview中显示的数据。然而,桌子总是空的。 另外,已经设置了委托和数据源,也调用了委托方法 在tableview中创建数据的方法: -(void) createCategoryData { NSMutableArray *categoriesForJiangSu; NSMutableArray *categoriesForZheJiang; categorySections=[[NSMuta

现在我已经创建了一个带有tableview的popoverController,并且创建了将在tableview中显示的数据。然而,桌子总是空的。 另外,已经设置了委托和数据源,也调用了委托方法

在tableview中创建数据的方法:

-(void) createCategoryData
{
NSMutableArray *categoriesForJiangSu;
NSMutableArray *categoriesForZheJiang;

categorySections=[[NSMutableArray alloc]initWithObjects:@"JiangSu",@"ZheJiang", nil];
categoriesForJiangSu=[[NSMutableArray alloc]init];
categoriesForZheJiang=[[NSMutableArray alloc]init];

[categoriesForJiangSu addObject:[[NSMutableDictionary alloc]initWithObjectsAndKeys:@"package 1",@"name",
                                 @"JiangSu.jpg",@"picture",nil]];
[categoriesForJiangSu addObject:[[NSMutableDictionary alloc]initWithObjectsAndKeys:@"package 2",@"name",
                                 @"JiangSu.jpg",@"picture",nil]];
[categoriesForZheJiang addObject:[[NSMutableDictionary alloc]initWithObjectsAndKeys:@"package 1",@"name",
                                  @"ZheJiang.jpg",@"picture",nil]];
[categoriesForZheJiang addObject:[[NSMutableDictionary alloc]initWithObjectsAndKeys:@"package 2",@"name",
                                  @"ZheJiang.jpg",@"picture",nil]];

categoryData=[[NSMutableArray alloc]initWithObjects:categoriesForJiangSu,categoriesForZheJiang, nil];
[categoriesForJiangSu release];
[categoriesForZheJiang release];


}
以下是委托方法:

-(NSInteger)numberOfSections
{
return [categorySections count];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [[categoryData objectAtIndex:section] count];
}

-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:     (NSInteger)section
{
return [categorySections objectAtIndex:section];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier=@"Cell";
UITableViewCell *cell=(UITableViewCell*)[tableView
                                           dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell==nil)
{
    cell=[[[UITableViewCell alloc]
           initWithStyle:UITableViewCellStyleDefault 
           reuseIdentifier:CellIdentifier] autorelease];
}
[[cell imageView] setImage:[UIImage imageNamed:[[[categoryData
                                                  objectAtIndex:indexPath.section] objectAtIndex:indexPath.row]
                                                objectForKey:@"picture"]]];

[[cell textLabel] setText:[[[categoryData objectAtIndex:indexPath.section]
                            objectAtIndex:indexPath.row] objectForKey:@"name"]];
cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
popoverController的viewDidLoad方法:

- (void)viewDidLoad
{
[self createCategoryData];
self.contentSizeForViewInPopover=CGSizeMake(200.0, 320.0);
[super viewDidLoad];
}
-(IBAction)showPopover:(id)sender
{
if(popoverController==nil)
{
    popoverController=[[UIPopoverController alloc]
                       initWithContentViewController:popoverContentViewController];
    [popoverController presentPopoverFromBarButtonItem:sender   permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
    popoverController.delegate=self;
}
}
以及mainViewController中的showPopover方法:

- (void)viewDidLoad
{
[self createCategoryData];
self.contentSizeForViewInPopover=CGSizeMake(200.0, 320.0);
[super viewDidLoad];
}
-(IBAction)showPopover:(id)sender
{
if(popoverController==nil)
{
    popoverController=[[UIPopoverController alloc]
                       initWithContentViewController:popoverContentViewController];
    [popoverController presentPopoverFromBarButtonItem:sender   permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
    popoverController.delegate=self;
}
}

popoverContentViewController是popoverController的名称。

作为初学者,如果您不清楚xib的概念,请不要使用xib。最好按照CodaFi的建议,在没有xib的情况下完成工作。将您的表视图添加到传递给popoverController的控制器视图。

您需要向我们提供一些有关您尝试的详细信息。我假设你是用代码做的?向我们展示您的一些代码…很难用您提供的一点帮助您。在我看来,您似乎从未将表添加为子视图。@CodaFi我是ios的初学者,因此您能告诉我如何将表添加为子视图吗?[self.view addSubview:self.nameOfMyTable]@CodaFi不,它不起作用。。。实际上,在popoverController.xib文件中,我拖入了一个tableView,因此我不确定是否有必要将我的表添加为子视图。我按照你的要求做了,我在没有xib的情况下完成了工作,但它也不起作用。我现在真的快疯了,我不知道问题出在哪里