2014-02-17 127 views
-3

我創造的一些記錄數組,並希望進行電話設施選擇任何cell..like 8904490035打電話給

-(void)viewDidLoad { 
    arryAppleProducts = [[NSArray alloc] initWithObjects:@"8904490035",@"iPod",@"MacBook",@"MacBook Pro",nil]; 
    arryAdobeSoftwares = [[NSArray alloc] initWithObjects:@"Flex",@"AIR",@"Flash",@"Photoshop",nil]; 
    arryAdobeSoftwares1 = [[NSArray alloc] initWithObjects:@"one",@"two",@"three",@"four",nil]; 
    self.title = @"Simple Table Exmaple"; 

    [super viewDidLoad]; 
} 

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    NextViewController *nextController = [[NextViewController alloc] initWithNibName:@"NextView" bundle:nil]; 
    [self.navigationController pushViewController:nextController animated:YES]; 

    if(indexPath.section == 0) 
     [nextController changeProductText:[arryAppleProducts objectAtIndex:indexPath.row]]; 
    else if(indexPath.section==1) 
     [nextController changeProductText:[arryAdobeSoftwares objectAtIndex:indexPath.row]]; 
    else 
     [nextController changeProductText:[arryAdobeSoftwares1 objectAtIndex:indexPath.row]]; 
} 
+1

不清楚你在問什麼 –

+1

你想要做什麼didSelectRowAtIndexPath –

+0

對於電話呼叫使用[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@「tel:42342334234」]]; – cjd

回答

1

1)時,對於來自arryAppleProducts我們下面調用動態對象:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel:%@",[arryAppleProductsobjectAtIndex:indexPath.row]]]]; 

2)調用特定的一個沒有arryAppleProducts的第一目的使用以下:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel:%@",[arryAppleProducts objectAtIndex:0]]]]; 

通過更換0作爲每個陣列

3)的對象的你的需要數目對於主叫特定數目使用以下:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel:8904490035"]]]; 
+0

Frndu請格式答案。 –

0

添加一個方法這樣&然後從tableViewDidSelectRowAtIndexPath

-(void)callOnMobile:(NSString *)phone { 
self.phoneNumber = phone; 
if(phone.length) { 
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel://%@", self.phoneNumber]]]; 
}else { 
     UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Phone Call" 
                message:@"Number Invalid" 
                delegate:self 
             cancelButtonTitle:@"Dismiss" 
             otherButtonTitles:nil, nil]; 
     [alert show]; 
    } 
} 


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
NextViewController *nextController = [[NextViewController alloc] initWithNibName:@"NextView" bundle:nil]; 
[self.navigationController pushViewController:nextController animated:YES]; 

if(indexPath.section == 0) 
    [nextController changeProductText:[arryAppleProducts objectAtIndex:indexPath.row]]; 
    [self callOnMobile:[arryAppleProducts objectAtIndex:indexPath.row]]; 
    ... 
    ... 
else if(indexPath.section==1) 
    [nextController changeProductText:[arryAdobeSoftwares objectAtIndex:indexPath.row]]; 
else 
    [nextController changeProductText:[arryAdobeSoftwares1 objectAtIndex:indexPath.row]]; 
} 
調用它

這將解決你的目的。