1

我有一个非常棘手的问题,经过长时间的搜索(谷歌,stackoverflow,...)我没有得到适合我的解决方案。

让我介绍一下我目前选择的架构:

  1. 我有一个 AppDelegate,它有一个包含 UINavigationController 的 UIView 和应用程序 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. 这最终导致以下屏幕(正如我想要的那样): View iOS Mockup of current result

问题: 我现在的问题是,我只能点击刷新按钮。无法单击其他两个按钮(信息和注销)。我不明白为什么?我在这里做错了什么?

非常感谢您的帮助!

4

2 回答 2

0

尝试像第一个按钮(刷新)一样自动释放后两个按钮。

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 回答