[英]adding uibutton to a detail view programmatically
如何添加一個可以顯示電話號碼的uibutton並呼叫該號碼,以自動方式從每個表視圖單元的數組中加載數據
舉一個很好的例子:
NSString *phoneStr = [NSString stringWithFormat:@"tel:%@",[self.contactDetails objectForKey:@"phone"]];
NSString *escaped = [phoneStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:escaped]];
在每個單元格中放置一個按鈕,並將文本設置為數組中的電話號碼。 然后,在按鈕的按下選擇器上,調用URL tel:<PHONE NUMBER>:
- (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath {
...
UIButton *callButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[callButton addTarget:self selector:@selector(callButtonPressed:)];
[callButton setTitle:@"<PHONE NUMBER>"];
[cell addSubview:callButton];
}
- (void)callButtonPressed:(id)sender {
NSString *phoneURLAsString = [NSString stringWithFormat:@"tel:%@", sender.currentTitle];
NSString *escapedPhoneURLAsString = [phoneURLAsString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:escapedPhoneURLAsString]];
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.