简体   繁体   English

将前缀tel:添加到数组中的电话号码变量

[英]adding prefix tel: to phone number variable from array

How I can add prefix tel: 65 to my phone number, that I fetched from address book in array. 如何将前缀tel: 65添加到我从阵列中的地址簿中获取的电话号码。

If I do this in viewdidload it's getting null 如果我在viewdidload中执行此操作,它将变为null

NSURL *phoneUrl = [NSURL URLWithString:[NSString stringWithFormat:@"tel:%@", phoneNumbers]];
    NSLog(@"Some Text %@", phoneUrl);
    NSLog(@"Phone Numbers %@", phoneNumbers);

Here phoneNumbers is array with numbers per each contact 这里phoneNumbers是每个联系人都有电话号码的数组

Udate: Udate:

- (void)viewDidLoad
{
    [super viewDidLoad];

    [self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"BG.jpg"]]];
    [detailTableView setBackgroundColor:[UIColor clearColor]];
    detailTableView.separatorStyle = UITableViewCellSeparatorStyleNone;

    ShadowTable *Shadow = [[ShadowTable alloc] init];
    [Shadow ForTableView:detailTableView ForView:self.view HeaderAlpha:0.3 FooterAlpha:0.6];

    for(int i = 0 ; i <[phoneNumbers count]; i++)
    {
        NSURL *phoneUrl = [NSURL URLWithString:[NSString stringWithFormat:@"tel:%@", [phoneNumbers objectAtIndex:i]]];
        NSLog(@"Phone with URL %@", phoneUrl);
        NSLog(@"Phone Numbers %@", phoneNumbers);
    }


}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return [phoneTypes count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    UILabel *typeLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 10, 100, 40)];
    typeLabel.text = [phoneTypes objectAtIndex:indexPath.row];
    [typeLabel setBackgroundColor:[UIColor clearColor]];
    [cell addSubview:typeLabel];



    UILabel *numberLabel = [[UILabel alloc] initWithFrame:CGRectMake(130, 10, 170, 40)];
    numberLabel.text = [phoneNumbers objectAtIndex:indexPath.row];
    [numberLabel setBackgroundColor:[UIColor clearColor]];
    [cell addSubview:numberLabel];

    if (indexPath.row %2 == 0) {

        cell.contentView.backgroundColor = [UIColor colorWithRed:0.95 green:0.95 blue:0.95 alpha:1.0];
    } else {

        cell.contentView.backgroundColor = [UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:1.0];
    }

    //cell.textLabel.text = [phoneNumbers objectAtIndex:indexPath.row];

    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

You are using an array not a string. 您正在使用数组而不是字符串。 So you need to access all elements of array to add as suffix. 因此,您需要访问数组的所有元素以添加为后缀。

Use this : 用这个 :

for(int i = 0 ; i <[phoneNumbers count]; i++)
{
    NSString *str = [@"tel:" stringByAppendingFormat:@"%@",[phoneNumbers objectAtIndex:i]];
str = [str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *phoneUrl = [NSURL URLWithString:str];
NSLog(@"Some Text %@", phoneUrl);
}

EDIT : Url was null because there were spaces in "2013-05-31 14:58:24.759 GTCallBack[8225:c07]" so encode it to remove spaces. 编辑:网址为null,因为“ 2013-05-31 14:58:24.759 GTCallBack [8225:c07]”中有空格,因此对其进行编码以删除空格。 Hope it helps you. 希望对您有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM