2010-11-10 55 views
0

我有一個名爲sectionNamesArray的NSMutableArray填充的UIPickerView。當一個項目被添加到sectionNamesArray時,我如何手動獲取這個委託被調用?更新UIPickerView行數

-- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component 

{ 

return ([sectionNamesArray count] + 1); 

} 

問題是我把這個pickerView添加到titleView中navBar的中心。如果我嘗試刪除UIPickerView並重新分配它,以便再次調用委託,PickerView將顯示在導航欄的左側,而不是中心。我猜測也許界面生成器設置在中心......?

下面是該代碼:

-(void) setupPickerView{ 
myPickerView = nil; 
myPickerView = [[UIPickerView alloc] init]; 
myPickerView.backgroundColor = [UIColor clearColor]; 
myPickerView.delegate = self; 
myPickerView.dataSource = self; 
myPickerView.showsSelectionIndicator = YES; 
[self.navigationController.navigationBar setBackgroundView:myPickerView]; 

CGSize pickerSize = [myPickerView sizeThatFits:CGSizeZero]; 
UIView *pickerTransformView = [[UIView alloc] initWithFrame:CGRectMake(-40.0, -43.0, pickerSize.width, pickerSize.height)]; 
pickerTransformView.transform = CGAffineTransformMakeScale(.55f, .55f); 

[pickerTransformView addSubview:myPickerView]; 
[self.navigationController.navigationBar setBackgroundView:pickerTransformView]; 

} 

回答

4

當你添加了一些你的陣列不能使用[UIPickerView reloadAllComponents]- (void)reloadComponent:(NSInteger)component

這很可能會查詢您的委託並調用檢查數組並重新加載視圖所需的所有內容。

+0

真棒的想法。我不知道它存在。我現在就試一試。大多數對象是否有重載所有內容的方法?我知道tableview呢。 – Bryan 2010-11-11 01:04:03

+0

完美運作。如果我推動一個模式視圖控制器,我怎麼能從我的其他viewController調用這個函數,因爲它會自行解除它?非常感謝! – Bryan 2010-11-11 01:16:20