我搜索了所有问题,似乎无法找到答案。
我有以下IBAction。每次点击电话号码时都会崩溃。我已经回到数据库并将电话号码格式化为5551235555而不是(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];
}
任何代码指南都会受到关注。
答案 0 :(得分:0)
Bar *items = self.detailItem;
未启动,因此它返回nil。请尝试以下方法:
Bar *items = [[Bar alloc] init];
items = self.detailItem;
或者你应该做的是让 items
成为这个特定班级的ivar。然后,您可以启动items
一次并在整个课程中使用它。