0 Replies - 6247 Views - Last Post: 05 July 2012 - 01:03 PM

#1 gram999   User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 89
  • Joined: 21-January 08

Updating code form View Based project to work in Single View template

Posted 05 July 2012 - 01:03 PM

Good day everyone! I am a newbie with regard to Objective-C and was wondering if I might be able to get some help with the code below. It is a simple tip calculator for the iPhone that uses a data picker at the bottom of the view for the tip percentage, a text box to enter the bill amount and a label to describe the prescribed tip. It is from an Xcode tutorial that was orginially coded as a View Based Application using a View Based Template. I have been trying to update the code so it will work with the Single View template in Xcode 4.2 The code is listed below. It will build successfully but it crashes at a spot just after the @implementation in ViewController.M file. Specifically it appears to be throwing the error at the billTotal.Delegate = self; line which refers to the text box in the UI where the user would insert the total amount that they are calculating the tip for. From the warning in the line it appears that it is a delegate issue but I just do not have enough knowledge in Objective-C yet to know how to effectively address it. I have tried inserting an @property line in the Delgate file but have not had any success. I am stuck at the moment. Any suggestions are greatly appreciated. Thank you in advance.

Here is the code:

// ViewController.h    

#import <UIKit/UIKit>

@interface ProCentViewController : UIViewController { 

IBOutlet UITextField *BillTotal; 

IBOutlet UILabel *tipAmount; 

IBOutlet UIPickerView *tipPicker; 

NSMutableArray *PickerViewArray; 

float tipSelected; 



// ProCentViewController.m 

@implementation ProCentViewController 

-(void) viewDidLoad { 

[super viewDidLoad]; 

BillTotal.delegate = self;  (Error is thrown at this line. Warning is: "Assigning to id' <UITextfieldDelegate> from incompatible type ViewController")

PickerViewArray = [[NSMutableArray alloc] init]; 

for(int i = 1; i <= 20; i ++) { NSString *myString = [NSString stringWithFormat:@"%d%%", i]; 

[PickerViewArray addObject:myString]; 



-(BOOL) textFieldShouldReturn:(UITextField*) textField { 

[textField resignFirstResponder]; return YES;


-(NSInteger) NumberofComponentsInPickerView: (UIPickerView *) thePickerView{ return 1; 


-(NSInteger) pickerview: (UIPickerView *) thePickerViewNumberofRowsInComponent: (NSInteger) component{

return [PickerViewArray count]; 


-(NSString *) pickerview: (UIPickerView *) thePickerViewtitleForRow: (NSInteger)RowforComponent:(NSInteger) component{ 

return [PickerViewArray objectAtIndex:RowforComponent]; 


-(void)pickerView:(UIPickerView *) thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component { 

tipSelected = row + 1; tipSelected = tipSelected / 100; 

float tipTotal = [BillTotal.text floatValue] *tipSelected; 

tipAmount.text = [NSString stringWithFormat:@"Tip: $%2f", tipTotal]; 



Is This A Good Question/Topic? 0
  • +

Page 1 of 1