1

私は非常にトリッキーな問題を抱えており、長い間検索した後(Google、stackoverflowなど)、自分に合った解決策が得られませんでした。

私が現在選択しているアーキテクチャを紹介しましょう。

  1. UINavigationController を含む UIView を持つ AppDelegate があり、アプリケーション didFinishLaunchingWithOptions: には以下が含まれます。

    UIView *myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 400)];
      UIViewController *myController = [[UIViewController alloc] init];
      myController.view = myView;
    
    
          FSCScrumRootView * myRootView = [[FSCScrumRootView alloc] initWithNibName:@"FSCScrumRootView" bundle:[NSBundle mainBundle]];
    
          [myController.view addSubview:myRootView.navigation.view];
    
          [self.window addSubview:myController.view];
    
          [self.window makeKeyAndVisible];
          return YES;
        }
    
  2. 私の FSCScrumRootView (UIViewController から継承) では、次のようにビューを初期化します。

    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
    { 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    
    if (self) {
    // Custom initialization
    self.navigation = [[[UINavigationController alloc] init] autorelease];
    self.scrumProjectsList = [[[FSCScrumProjectListView alloc] init] initWithNibName:@"FSCScrumProjectListView" bundle:nil];
    [navigation pushViewController:scrumProjectsList animated:YES]; 
    
    [navigation view]; 
    } 
    return self; 
    } 
    
  3. 私の FSCScrumProjectListView (UITableViewController から継承されます) では、次のように viewDidLoad を実装しました。

    - (void)viewDidLoad 
    { 
    [super viewDidLoad]; 
    
    //Set the title 
    self.navigationItem.title = @"Scrum Projects";
    
    UIBarButtonItem *myRefreshButton = [[[UIBarButtonItem alloc] initWithTitle:@"Refresh" style:UIBarButtonSystemItemRefresh target:self action:@selector(refreshList)] autorelease]; 
    self.navigationItem.leftBarButtonItem = myRefreshButton;
    
    UIBarButtonItem *myLogoutButton = [[UIBarButtonItem alloc] initWithTitle:@"Logout" style:UIBarButtonSystemItemCancel target:self action:@selector(logout)]; 
    self.navigationItem.rightBarButtonItem = myLogoutButton;
    
    
    //Initialize the toolbar
    toolbar = [[UIToolbar alloc] init];
    toolbar.barStyle = UIBarStyleDefault;
    
    //Set the toolbar to fit the width of the app.
    [toolbar sizeToFit];
    
    //Caclulate the height of the toolbar
    CGFloat toolbarHeight = [toolbar frame].size.height;
    
    //Get the bounds of the parent view
    CGRect rootViewBounds = self.parentViewController.view.bounds;
    
    //Get the height of the parent view.
    CGFloat rootViewHeight = CGRectGetHeight(rootViewBounds);
    
    //Get the width of the parent view,
    CGFloat rootViewWidth = CGRectGetWidth(rootViewBounds);
    
    //Create a rectangle for the toolbar
    CGRect rectArea = CGRectMake(0, rootViewHeight - toolbarHeight, rootViewWidth, toolbarHeight);
    
    //Reposition and resize the receiver
    [toolbar setFrame:rectArea];
    
    //Create a button
    UIBarButtonItem *infoButton = [[UIBarButtonItem alloc] 
                                 initWithTitle:@"Info" style:UIBarButtonItemStyleBordered target:self action:@selector(info_clicked:)];
    
    [toolbar setItems:[NSArray arrayWithObjects:infoButton,nil]];
    
    //Add the toolbar as a subview to the navigation controller.
    [self.navigationController.view addSubview:toolbar];
    
    //Reload the table view
    [self.tableView reloadData]; 
    }
    
  4. これにより、最終的に次の画面が表示されます (希望どおり): 現在の結果の iOS モックアップを表示

問題: 私の問題は、[更新] ボタンしかクリックできないことです。他の 2 つのボタン (Info と Logout) はクリックできません。そして、私はなぜ理解していないのですか?ここで何が間違っていますか?

あなたの助けは親切に感謝されます!

4

2 に答える 2

0

最初のボタン (更新) のように、2 番目の 2 つのボタンを自動解放してみてください。

UIBarButtonItem *myLogoutButton = [[[UIBarButtonItem alloc] initWithTitle:@"Logout" style:UIBarButtonSystemItemCancel target:self action:@selector(logout)]autorelease];



UIBarButtonItem *infoButton = [[[UIBarButtonItem alloc] 
                             initWithTitle:@"Info" style:UIBarButtonItemStyleBordered target:self action:@selector(info_clicked:)]autorelease];
于 2011-04-29T14:06:18.007 に答える
0

みんな、私は自分の問題の理由を見つけました。

このプロジェクトの最初の行は、すべての問題を担当していました。

UIView *myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 400)];

そこで作成したビューのサイズは 200x400 しかないため、このビューの外側に表示されるイベントを認識するには小さすぎます (ただし、すべてが表示されます)。

このビューのサイズを変更すると、すべてが期待どおりに機能します。

UIView *myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 500)];

しかし、より動的な解決策はおそらく次のようになります。

CGRect cgRect =[[UIScreen mainScreen] bounds];
CGSize cgSize = cgRect.size;
UIView *myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, cgSize.width, cgSize.height)];

動的な画面サイズを取得するためのさらに良い解決策があるでしょうか?

于 2011-05-02T12:36:52.383 に答える