讓NSMutableArray
按距離排序。所以我需要一個呼叫按鈕或標籤UINavigationBar
(右鍵)與調用函數使用字典和valueKey。我怎麼能意識到它?導航欄中的呼叫按鈕
下面是代碼,我使用的是:
- (void)updateViewWithDict:(NSDictionary*)dic {
NSString *str = [NSString stringWithFormat:@"%@\nAddress: %@\nPhone: %@\n\nWorkTime:\n%@", [dic valueForKey:@"name"], [dic valueForKey:@"address"], [dic valueForKey:@"phone"], [dic valueForKey:@"workTime"]];
UILabel *nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 110, 300, 140)];
nameLabel.textAlignment = NSTextAlignmentLeft;
nameLabel.numberOfLines = 0;
nameLabel.text = str;
nameLabel.textColor = [UIColor whiteColor];
nameLabel.font = [UIFont fontWithName:@"HelveticaNeue" size:14.0];
UIBarButtonItem *callButton = [[UIBarButtonItem alloc] initWithTitle:@"Call"
style:UIBarButtonItemStyleDone target:nil action:nil];
self.navigationItem.rightBarButtonItem = callButton;
}
我不能得到如何分配NSURL
我的按鈕?
我試圖使用這樣的代碼..但接下來呢?
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel://%@",[dic valueForKey:@"phone"]]]];
===
解決方案: - 我發現像這樣的方式:
在- (void)updateViewWithDict:(NSDictionary*)dic
我寫if語句
if ([[dic valueForKey:@"phone"] isEqual: @"12345"]){
UIBarButtonItem *callButton = [[UIBarButtonItem alloc] initWithTitle:@"Call" style:UIBarButtonItemStyleDone target:self action:@selector(FirstOffice:)];
self.navigationItem.rightBarButtonItem = callButton;
}
else if ([[dic valueForKey:@"phone"] isEqual: @"67890]){
UIBarButtonItem *callButton2 = [[UIBarButtonItem alloc] initWithTitle:@"Call" style:UIBarButtonItemStyleDone target:self action:@selector(SecondOffice:)];
self.navigationItem.rightBarButtonItem = callButton2;
}
和方法,這樣
- (void)FirstOffice:(UIBarButtonItem*)sender {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel://12345"]]];
}
- (void)SecondOffice:(UIBarButtonItem*)sender {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel://67890"]]];
}
也許還有另一種方式?更簡單的方法)謝謝
我想這樣的事情,但在虛空方法[DIC valueForKey ...]不認識... – diegogabisonia
'-objectForKey:'使用詞典交互時英寸 – Hyperbole
編輯我的答案。 – dasdom