2011-04-18 33 views
-1

我正在嘗試顯示帳單總額與帳單金額相結合的帳單總計結果。以下是我收到錯誤的代碼行的副本。任何幫助深表感謝。顯示帳單總計結果的問題

 [totalBillCost setText:[NSString stringWithFormat:@"$ %.2f", ([costWithTipLabel] + costWithoutTip]); 

下面是整個代碼的副本:

#import "tipcalcViewController.h" 

@implementation tipcalcViewController 


- (void)dealloc 
{ 

    [super dealloc]; 
} 
- (IBAction)aSliderChanged:(id)sender { 
    UISlider *slider = (UISlider *)sender; 
    if (slider == tipslide) { 
     NSString *tip = [NSString stringWithFormat:@"%.2f", slider.value * 100]; 
     int tipPercentage = [tip intValue]; 
     NSString *multiplier; 
     if (tipPercentage < 10) { 
      multiplier = [NSString stringWithFormat:@"1.0%i", tipPercentage]; 
     } 
     else if (tipPercentage >= 10) { 
      multiplier = [NSString stringWithFormat:@"1.%i", tipPercentage]; 
     } 
     NSString *tt = [[costWithoutTip text] stringByReplacingOccurrencesOfString:@"$ " withString:@""]; 
     [costWithTipLabel setText:[NSString stringWithFormat:@"$ %.2f", ([tt intValue]/tipPercentage)]]; 
     [tipTextLabel setText:[[NSString stringWithFormat:@"Tip(%i", tipPercentage] stringByAppendingString:@"%):"]]; 
     [self performSelector:@selector(updateNumOfPeop)]; 
    } 
    else if (slider == peopleslide) { 
     NSString *p = [NSString stringWithFormat:@"%.f", slider.value*10]; 
     int numberOfPeople = [p intValue]; 
     [numberOfPeopleTextLabel setText:[NSString stringWithFormat:@"Each(%i):", numberOfPeople]]; 
     NSString *tt = [[costWithoutTip text] stringByReplacingOccurrencesOfString:@"$ " withString:@""]; 
     [numberOfPeopleLabel setText:[NSString stringWithFormat:@"$ %.2f", [tt floatValue]/numberOfPeople]]; 
    } 
    [totalBillCost setText:[NSString stringWithFormat:@"$ %.2f", ([costWithTipLabel] + costWithoutTip]); 



} 
- (void)updateNumOfPeop { 
    NSString *p = [NSString stringWithFormat:@"%.f", peopleslide.value*10]; 
    int numberOfPeople = [p intValue]; 
    [numberOfPeopleTextLabel setText:[NSString stringWithFormat:@"Each(%i):", numberOfPeople]]; 
    [numberOfPeopleLabel setText:[NSString stringWithFormat:@"%.2f", [[costWithTipLabel text] floatValue]/numberOfPeople]]; 
} 

          - (void)viewDidLoad { 
    [costWithoutTip becomeFirstResponder]; 
    [costWithoutTip setDelegate:self]; 
    [costWithoutTip setKeyboardType:UIKeyboardTypeNumbersAndPunctuation]; 
    [tipslide setValue:0.01]; 
    [peopleslide setValue:0.1]; 
    [super viewDidLoad]; 
} 
- (void)textFieldDidEndEditing:(UITextField *)textField { 
    [costWithoutTip setText:[NSString stringWithFormat:@"$ %.2f", [costWithoutTip text].floatValue]]; 
    [costWithoutTip resignFirstResponder]; 
} 
- (BOOL)textFieldShouldReturn:(UITextField *)textField { 
    [costWithoutTip resignFirstResponder]; 
    return YES; 
} 
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField { 
    [costWithoutTip resignFirstResponder]; 
    return YES; 
} 
- (void)didReceiveMemoryWarning 
{ 
    // Releases the view if it doesn't have a superview. 
    [super didReceiveMemoryWarning]; 

    // Release any cached data, images, etc that aren't in use. 
} 

#pragma mark - View lifecycle 

/* 
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib. 
- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
} 
*/ 

- (void)viewDidUnload 
{ 
    [super viewDidUnload]; 
    // Release any retained subviews of the main view. 
    // e.g. self.myOutlet = nil; 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    // Return YES for supported orientations 
    return (interfaceOrientation == UIInterfaceOrientationPortrait); 
} 

@end 
+0

而錯誤是? – 2011-04-18 16:40:46

+0

錯誤:預期「:」前「]」令牌 從先前的錯誤,拯救 錯誤:解析問題:預期標識符 – Dominick 2011-04-18 16:42:00

+0

我們幫不了你,除非你告訴我們是什麼問題:請包括錯誤在問題主體中。該消息意味着一個簡單的語法錯誤。你有一個錯位的方括號。 – 2011-04-18 18:18:03

回答

1

看來,如果你搞砸了括號:

[totalBillCost setText:[NSString stringWithFormat:@"$ %.2f", ([costWithTipLabel] + costWithoutTip]); 

這應該是:

[totalBillCost setText:[NSString stringWithFormat:@"$ %.2f", ([costWithTipLabel] + costWithoutTip)]];