0

だから私は以下に示すコードの一部を使用して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

編集:これは私がポップオーバーで見るものです

ここに画像の説明を入力してください

4

4 に答える 4

0

viewDidLoad追加しましたself.tableView = [[UITableView alloc] init]

于 2012-08-20T05:23:16.880 に答える
0

UITableViewController は暗黙的にデータソースとデリゲートを設定するため、データソースとデリゲートを明示的に設定する必要はありません。

.h ファイルから UITableViewDataSource、UITableViewDelegate を削除します

 #import <UIKit/UIKit.h>

@protocol KLActionsViewControllerDelegate
 - (void)actionSelected:(NSInteger)index;
@end

  @interface KLActionsViewController : UITableViewController 
 @property (nonatomic, retain) NSMutableArray* actionList;
 @property (nonatomic, assign) id<KLActionsViewControllerDelegate> delegate;


 @end

また、この行を削除します**actionsController.delegate = self;

  vc = [[ActionsViewController alloc] init];
 actionsController = [[UIPopoverController alloc] initWithContentViewController:vc];
  [actionsController presentPopoverFromBarButtonItem:(UIBarButtonItem*)sender  permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
于 2013-09-24T13:13:17.263 に答える
0

問題はその行にあると思います:

vc = [[ActionsViewController alloc] init];

NIB ファイルがある場合は、UIViewControllerそれを使用してロードする必要があります。

vc = [[ActionsViewController alloc] initWithNibName:@"ActionViewController" bundle:nil];
// the NibName must be the exact name of XIB file without extension.

または

次を設定する必要がありますpopoverContentSize

[actionController setPopoverContentSize:vc.view.frame.size];

少しでもお役に立てば幸いです。


アップデート:

問題ではないようです。UIPopoverController単純なUITableViewControllerデリゲートの問題です。

その行で:

actionsController.delegate = self;

を実装するデリゲートとしてそのクラスを設定する必要がありますUITableViewDelegate。基本的にはUITableViewControllerそれ自体が好きです

actionsController.delegate = actionController;

したがって、新しいデリゲート クラスが存在するデリゲート コールバック メソッドを実装していない場合は、これを置き換えないでください。selfコールバックに応答するために実際に委任されたクラスからチャンスを盗むだけで、新しいデリゲート クラスではコールバックに応答しません。

これが、データのない空のテーブルが表示される理由です。

于 2012-08-19T08:51:38.237 に答える
0

(viewdidload の最後の行:

 [self.tableView reloadData];
  • これにより、テーブル ビュー メソッドが実行されます。さまざまな tableview メソッド、特に - (NSInteger)numberOfRowsInSection:(NSInteger)section { return [self.actionList count]; にブレークポイントを配置します。これが呼び出されない場合、テーブルビューはロードされていません。
于 2013-09-24T08:45:18.800 に答える