Call phone number from UIButton - xcode

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.

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.

Related

UIImage in-between text in UIAlertView

How would I be able to have an image show in a UIAlertView along with some text. Apparently this isn't available in iOS7, is this true? All I want is to replace some text with an image, preferably not by using custom libraries. The NSString *formula is the one I want to replace with an image.
NSString *title = [NSString stringWithFormat:#"BMI"];
NSString *mess = [NSString stringWithFormat:#"Body Mass Index, or BMI, is used by many health professionals to assess a patient's health. BMI is calculated by the formula:"];
NSString *formula = [NSString stringWithFormat:#" Weight(kg)/(Height(m)*Height(m))"];
// Combined message (mess) and Formula (formula)
NSString *combinedMess;
combinedMess = [mess stringByAppendingString:formula];
NSString *mess1 = [NSString stringWithFormat:#" Although this tool is useful in measuring a person's weight ratio, it becomes unrealiable for body builders and other extremes. BMI combined with a general indication of fitness level gives Quick Fit a clear view of the fitness level of the user."];
// Combined message (combinedMess) and message (mess1)
NSString *all;
all = [combinedMess stringByAppendingString:mess1];
UIAlertView *alert = [[UIAlertView alloc]initWithTitle: title
message: all
delegate: self
cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
[alert show];
This is not possible on iOS7 without creating your own version of an alert view. A quick google search came across this https://github.com/wimagguc/ios-custom-alertview which looks promising.
Per apple's documentation:
Subclassing Notes
The UIAlertView class is intended to be used as-is
and does not support subclassing. The view hierarchy for this class is
private and must not be modified.
https://developer.apple.com/library/ios/documentation/uikit/reference/UIAlertView_Class/UIAlertView/UIAlertView.html

Looping Through NSArray

This is suppose to play all the songs in the NSArray but it only plays one and stops. What am I doing wrong? The array contains a whole bunch of links to different .mp3 formatted songs.
NSArray *array = [myString componentsSeparatedByString:#"\n"];
int nextTag = 1;
for (soundPath in array) {
NSURL *url = [NSURL URLWithString:soundPath];
asset = [AVURLAsset URLAssetWithURL:url options:nil];
yourMediaPlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
yourMediaPlayer.controlStyle = MPMovieControlStyleNone;
yourMediaPlayer.currentPlaybackTime = 0;
yourMediaPlayer.shouldAutoplay = FALSE;
[yourMediaPlayer play];
nextTag++;
}
Instead of trying to get MPMoviePlayerController play a list of items use AVQueuePlayer instead. It has a convenient advanceToNextItem method.
You can create a player already loaded with items (class AVPlayerItem) either with initWithItems or queuePlayerWithItems. Then just call play on it (inherited from AVPlayer) and it should play the items one after the other.
See:
AVQueuePlayer docs
AVPlayer docs
AV Foundation Programming Guide
AVPlayerItem docs

UIPickerView Changing UIButton Title Size

So I'm making Alarm Clock to test my skills but can't seem to figure this out... What I've got a UIPickerView that gives a user a time that they can select. Once the time is selected the titleLabel on a UIButton is supposed to update with the time they selected and it does, but it shrinks the new time so it's unreadable... Is there something that needs adjusted with the formatting?
Before when my page loads
Here's my code
- (NSDate *)dateFromString:(NSString *)string {
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:#"HH:mm"];
NSDate *date = [[NSDate alloc] init];
date = [formatter dateFromString:#"15:00"];
assert(date != nil); // Error converting string to date
return date;
}
After when a user has set a time
Any reason why it might be doing this?
You're experiencing middle truncation of the button's text, and there are a couple of cures for this. You can either make the button bigger by simply adjusting its frame. Or, you can adjust the text size of the title label:
[myButton.titleLabel setFont:[UIFont fontWithName:myButton.titleLabel.font.fontName size:10.0f]];
Actually this seemed to resolve the issue.
alarmButton.titleLabel.adjustsFontSizeToFitWidth = YES;

How to make second tabbarItem to be selected as default in iPhone?

I have added a UITabBarController programatically (Search,Login) and I want to set second tabbaritem(Login) and its view to be selected when Login credentials are not correct.But I m unable to do it so ..Could not understand where I m going wrong ..?
Search *first = [[Search alloc] initWithNibName:#"Search" bundle:nil];
first.title=#"Search";
Login *second=[[Login alloc]initWithNibName:#"Login" bundle:nil];
second.title=#"Login";
NSArray *viewArray= [NSArray arrayWithObjects:first,second, nil];
tabBarController=[[UITabBarController alloc] init];
[tabBarController setViewControllers:viewArray animated:NO];
[tabBarController setSelectedIndex:2];
[self presentModalViewController:tabBarController animated:NO];
But here my SearchViewController is selected and displayed as default...Where i m going wrong..?
Error is in this line:
[tabBarController setSelectedIndex:2];
Counting starts not from 1 but from 0, so in your case you have to change it to:
[tabBarController setSelectedIndex:1];

Thread 1: Program received signal:"Sigbart 1"

When I run the app in the iPhone Simulator, everything works just fine .. but with time I'll try to get my iPhone
Thread 1: Application Received
signal:" Sigbart 1"
why?
Here is the code:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
golfbaner *detailViewController = [[golfbaner alloc] initWithNibName:#"Golfbaner" bundle:nil];
detailViewController.golf = [banenavn objectAtIndex:indexPath.row];
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
}
XCode says it's HERE:
[self.navigationController pushViewController:detailViewController animated:YES];
it goes wrong
I can admit that I'm quite a beginner.... lol
seems to be u are new bee.so here i assume u would be created the golfbaner with nib file .so it would be same as filename for nibname.
Golfbaner.NIB is not with your project.//check out this
maybe like golfbaner.NIB
so use
golfbaner *detailViewController = [[golfbaner alloc] initWithNibName:#"golfbaner" bundle:nil];
Most likely is that detailViewController is nil. If you look at the console output it will tell you for certain.
The reason its nil on hardware is that the file system is case sensitive on hardware and hence
golfbaner *detailViewController = [[golfbaner alloc] initWithNibName:#"Golfbaner" bundle:nil];
"Golfbaner" != "golfbaner"
Check your nibname for case match. I suspect its "golfbaner.xib".
See iOS Objective-C Image file name/path different behavior betwewen simulator and device
As a style point class names should be capitalised otherwise it makes a class hard to separate from a variable when reading code.
It may be spelling mistake after #"Golfbaner"
just copy nibfile name and paste it.

Resources