iOS:我有这个UIToolBar,我试图摆脱单击按钮时

时间:2014-01-23 19:26:06

标签: ios objective-c uitoolbar

我试图让工具栏出现(有效),一旦出现我想点击完成按钮并关闭工具栏(不起作用)。我不知道该怎么做,我想通过删除pickerview它会起作用。我认为最大的问题是我的取消率方法没有被调用。

     pickerView = [[UIView alloc]initWithFrame:CGRectMake(0, 300, 180, 260)];

     rateToolbar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
     rateToolbar.barStyle = UIBarStyleBlackTranslucent;
     rateToolbar.items = [NSArray arrayWithObjects:
                       [[UIBarButtonItem alloc]initWithTitle:@"Done" style:UIBarButtonItemStyleBordered target:self action:@selector(cancelRate)],
                       [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil],

                       nil];
    [rateToolbar sizeToFit];

    [pickerView addSubview:rateToolbar];   
    [self.view addSubview:pickerView];

  -(void)cancelRate{
  [pickerView removeFromSuperview];
   }

1 个答案:

答案 0 :(得分:0)

我就是这样做的。

//PUT THIS CODE ON THE VIEWDIDLOAD EVENT
UIBarButtonItem *button2 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(pressReloadButton)];
        self.navigationItem.rightBarButtonItem = button2;

//THIS IS THE METHOD THAT IS CALLED
- (void)pressReloadButton{
    self.spinner.hidden = NO;
    [self.spinner startAnimating];
    [self refresh];
}

希望它有所帮助.. GL HF