[英]send data from tableviewcontroller to detailviewcontroller
[英]Data from DetailViewController not displaying
我正在使用一個正在使用的應用程序進行化學計算器細分,但是我無法獲取數據,也無法獲取信息以正確填充屏幕。 還有一個第二個問題,即一致性,如果有人可以幫助我,我將不勝感激,但這不是這個問題的主要重點-我將為此專門討論一個主題。
因此,我將介紹我想做的事情和嘗試過的事情。 我要做的是制作一個化學計算器,根據選擇的方程式,修改UIStepper的最大值/最小值。值修改為包括該方程式的所有可能推導以及某些顯示/隱藏的UILabel和UITextFields。
我已經確認我已經將數據從MasterViewController傳遞下來,因為我已經將數據設置為名為_equation的NSString,並成功使用_equation修改了viewDidLoad中self.title下的DetailViewController的標題。
我嘗試在viewDidLoad下的if / if else嵌套下適當地放置和初始化所有UIStepper屬性(它還將_equationName可能的值量化為整數(eqNum),以便可以在switch語句中使用)。 我也嘗試過將UITextField隱藏屬性放置在viewDidLoad下,無濟於事。
因此,事不宜遲,讓我們開始編寫代碼。 我已將代碼截斷為一個等式,因此您可以更輕松地了解此處發生的情況-請注意,該代碼嵌套在IBAction下的Calculate按鈕中:
// Take _equationName quantization and use it in a switch case to determine the formula that IBAction will use:
if (dflt)
{
switch (eqNum)
{
case 1:
if ((stepper.value = 1))
{
// Change deriv_units appropriately:
deriv_units.text = @"Energy (Joules)";
// This is a Planck's constant calculation, we hide the second variable as the constant
// is stored:
value2.hidden = YES;
value2_type.hidden = YES;
// Now we set up the parameters of the first entry variable:
value1_type.text = @"Frequency (in Hz)";
double frequency = [value1.text doubleValue];
double Planck = 6.626069e-34;
double energy = Planck * frequency;
// Now we set up the return field to return results:
NSString* resultIntermediate = [NSString stringWithFormat:@"%f", energy];
result.text = resultIntermediate;
units.text = @"J";
}
以及viewDidLoad下的后續代碼:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self configureView];
self.title = _equationName;
int eqNum;
if ((_equationName = @"Energy-Frequency Relation"))
{
eqNum = 1;
// Set stepper bounds for derivation:
[stepper setMinimumValue:1];
[stepper setMaximumValue:3];
self.stepper.stepValue = 1;
self.stepper.wraps = NO;
self.stepper.autorepeat = NO;
self.stepper.continuous = YES;
// This is primarily a two-variable equation, so hide UITextView and UILabel #3:
value3.hidden = YES;
value3_type.hidden = YES;
}
(向認識到這一點的人提供支持-這是普朗克的關系!:D)
這是GUI的外觀(如出現在Storyboard中):
這是在iOS模擬器中顯示的內容:
請注意未對准問題,這不是這里發生的主要問題。 還要注意,現在,方程式參數的switch語句位於if樹下,該樹檢查以查看dflt(分配給UISwitch的布爾變量)是否對雙精度計算返回true。 但是,將開關撥到ON位置后,此問題無法解決。
這里是一個更完整的解釋:
- value#.text是從頂部到底部在三個UITextField之一中輸入的數字。
- value#_type是要在相應的UILabel中顯示的文本。
- deriv_units是UILabel下方的一個標記為“ Derivation Units”的元素,用於顯示已使用UIStepper選擇方程式的哪個導數。
- 在底部:最右邊的UILabel是結果標簽,而最左邊的是單位標簽。
非常感謝能夠在編程正義道路上幫助這名新手開發人員的任何人。
關於對齊問題:在3.5英寸屏幕上運行時,好像正在為4英寸屏幕創建情節提要。 在右下角的情節提要中,有一些小按鈕,其中一個按鈕可讓您在4“或3.5”的顯示之間即時切換。
您確定控件已連接到代碼嗎?
- (void) viewDidAppear: (BOOL) animated{
[super viewDidAppear: animated];
// some rude NSAsserts, but let's be sure
NSAssert(value1_type != nil, @"Your control element is nil, it might not be hooked up");
// you should now see this text in the textfield
value1_type.text = @"Frequency (in Hz)";
NSAssert(result != nil, @"Your control element is nil, it might not be hooked up");
result.text = @"some test text";
NSAssert(units != nil, @"Your control element is nil, it might not be hooked up");
units.text = @"J";
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.