1

I've searched through all the questions and can't seem to find my answer.

I have the following IBAction. This is crashing every time you tap on the phone number. I have gone back to the DB and formatted the phone numbers to 5551235555 instead of (555)-123-5555.

- (IBAction)callPhone:(UIButton *)sender{

    Bar *items = self.detailItem;
    NSURL *pn = [NSURL URLWithString:[NSString stringWithFormat:@"tel:%@", items.barPhone]];
    [[UIApplication sharedApplication] openURL:pn];
}

- (void)setCallButton:(UIButton *)callButton{

    Bar *items = self.detailItem;
    [callButton setTitle:items.barPhone
                forState:UIControlStateNormal];
}

Any code guidance would be appriciated.

1 Answers1

0

Bar *items = self.detailItem; is not initiated, so that is why it is returning nil. Try the following:

Bar *items = [[Bar alloc] init];
items = self.detailItem;

Or what you should have done is make items an ivar for this particular class. Then you can initiate items once and use it throughout your class.

WrightsCS
  • 50,551
  • 22
  • 134
  • 186
  • There is nothing wrong with items, everything is reading correctly there. This info is a Segue from the TableView. There appears to be something wrong with creating 'pn'. It's nil but `items.barPhone` has the right value. – user1454340 Jul 16 '12 at 04:08
  • **pn** is nil. Try what I described above. If `items.barPhone` wasn't nil, pn wouldn't be nil. – WrightsCS Jul 16 '12 at 04:09
  • `items.barPhone` is not nil or it would not set the button Title correctly. I tried your code, assuming the `Bars` is supposed to be `Bar`. I get the same break – user1454340 Jul 16 '12 at 04:17
  • Okay, try adding `NSLog(@"Bar Item: %@",self.detailItem);` directly after `Bar *items = self.detailItem;` and see what it prints out in the console. – WrightsCS Jul 16 '12 at 04:22
  • I feel like an idiot. I must have accidently set a Breakpoint at this line. Removed that and everything is good. I thought I was losing my mind. – user1454340 Jul 16 '12 at 04:23