-1

我正在使用该WEPopoverViewcontroller课程。首先,我导入这个类,然后我添加这个代码:

 WEPopoverContentViewController.h
 {
   #import <UIKit/UIKit.h>

   @interface WEPopoverContentViewController : UITableViewController {
    NSArray *data;

  }
   @property(nonatomic,strong) NSArray *data;

   @end

   WEPopoverContentViewController.m
   {
    #import "WEPopoverContentViewController.h"


    @implementation WEPopoverContentViewController
    @synthesize data;


    #pragma mark -
    #pragma mark Initialization


    #pragma mark -
    #pragma mark View lifecycle

    - (void)viewDidLoad
    {
     [super viewDidLoad];
      self.contentSizeForViewInPopover = CGSizeMake(150, 3* 44 - 1);

      data=[[NSArray alloc]initWithObjects:@"rahul",@"sharma" ,nil];

  self.tableView.rowHeight = 44.0;
   self.view.backgroundColor = [UIColor clearColor];
       // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
         // self.navigationItem.rightBarButtonItem = self.editButtonItem;

} #pragma mark - #pragma mark 表格视图数据源

   - (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 [viewcont.data count];
       }

    // Customize the appearance of table view cells.
     - (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];
         }

        // Configure the cell...
     cell.textLabel.text = [NSString stringWithFormat:@"%@",[viewcont.data objectAtIndex:indexPath.row]];
           cell.textLabel.textColor = [UIColor whiteColor];
         return cell;
       }


        #pragma mark -
        #pragma mark Table view delegate

        - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
         {

         NSLog(@"selected index here");
      // Navigation logic may go here. Create and push another view controller.

      }

这个视图控制器用于显示 popoverTable 我在这里使用我的视图控制器代码.....

  ViewController.h
   {
   #import <UIKit/UIKit.h>


   @class WEPopoverController;
    @interface ViewController : UIViewController {

   WEPopoverController *popoverController;
   NSArray *data;
   UITableView *table;

  }
  @property (nonatomic, strong) WEPopoverController *popoverController;
  @property(nonatomic,strong)     NSArray *data;
  - (IBAction)onButtonClick:(UIButton *)button;

  @end

   }
  }

我使用以下代码创建了一个按钮:

      ViewController.m
      {
       - (IBAction)onButtonClick:(UIButton *)button {

      if (self.popoverController)`
        {
        [self.popoverController dismissPopoverAnimated:YES];
        self.popoverController = nil;
        [button setTitle:@"Show Popover" forState:UIControlStateNormal];
      }
       else


{
UIViewController *contentViewController = [[WEPopoverContentViewController alloc] initWithStyle:UITableViewStylePlain];
self.popoverController = [[WEPopoverController alloc] initWithContentViewController:contentViewController];
   self.contentSizeForViewInPopover = CGSizeMake(200, 200);
   data=[[NSArray alloc]initWithObjects:@"rahul",@"sharma", nil];
   NSLog(@"data %@",data);
   [self.popoverController presentPopoverFromRect:button.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
   [button setTitle:@"Hide Popover" forState:UIControlStateNormal];
}
  }
   }

使用此代码,我点击了此按钮,然后控制器进入WEPopoverContentViewController 并根据此WEPopoverContentViewController (NSArray *data)创建行中的创建数组成功显示弹出窗口,但我希望我想在其中创建此数组ViewController.m,然后显示弹出窗口,但是当我们在其中创建数组时ViewController如何显示弹出表这个显示空白表?

4

1 回答 1

0

在粘贴的按钮上使用此代码来填充表格并显示正确的方式......

    - (IBAction)onButtonClick:(UIButton *)button {

    if (self.popoverController)
    {
        [self.popoverController dismissPopoverAnimated:YES];
        self.popoverController = nil;
        [button setTitle:@"Show Popover" forState:UIControlStateNormal];
    }
    else
    {
        WEPopoverContentViewController *contentViewController = [[WEPopoverContentViewController alloc] initWithStyle:UITableViewStylePlain];
        self.popoverController = [[WEPopoverController alloc] initWithContentViewController:contentViewController];
        self.contentSizeForViewInPopover = CGSizeMake(200, 200);
         data1=[[NSArray alloc]initWithObjects:@"rahul",@"sharma", nil];
         NSLog(@"data %@",data1);
        contentViewController.data=(NSArray*)data1;
        [self.popoverController presentPopoverFromRect:button.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
        [button setTitle:@"Hide Popover" forState:UIControlStateNormal];
    }
}
于 2013-08-03T08:25:41.237 回答