從我的應用程序的編碼detailView具有分組表視圖。我希望應用程序撥打選定的電話號碼,或者發送文字或發送電子郵件(如果點擊電子郵件,並選擇地址後轉到Google地圖)。 這是我didSelectRowAtIndexPath ..和它不工作。我不知道如何獲取選定單元格的信息。請幫忙。如何撥打電話,發送文字或在地圖上查找地址?
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
Directory *text = (Directory *)[tableView cellForRowAtIndexPath:indexPath];
//check content of text.
NSLog(@"Phone Number Selected is %@", text);
//NSString *dialHome = [dispHomephone stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel:17148581499"]]
}
這裏是我的cellForRowAtIndexPath,如果它有幫助。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
int cellPhoneLen = [dispCellphone length];
int workPhoneLen = [dispWorkphone length];
int homePhoneLen = [dispHomephone length];
int emailLen = [dispEMail length];
NSString *address = [NSString stringWithFormat:@"%@\n"@"%@ %@ %@\n"@"%@", dispAddress, dispCity, dispState, dispZip, dispCountry];
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:CellIdentifier] autorelease];
}
cell.selectionStyle = UITableViewCellSelectionStyleBlue;
// Configure the cell...
switch (indexPath.section)
{
case 1:
{
if (homePhoneLen != 0)
{
switch (indexPath.row)
{
case 0:
{
if (homePhoneLen != 0)
{
cell.textLabel.text = NSLocalizedString(@"home :", @"homephone label");
cell.detailTextLabel.text = dispHomephone;
} break;
case 1:
if (workPhoneLen != 0)
{
cell.textLabel.text = NSLocalizedString(@"work :", @"workphone label");
cell.detailTextLabel.text = dispWorkphone;
} break;
case 2:
if (cellPhoneLen != 0)
{
cell.textLabel.text = NSLocalizedString(@"mobile :", @"cellphone label");
cell.detailTextLabel.text = dispCellphone;
}
}
}
}
else if (workPhoneLen != 0)
{
switch (indexPath.row)
{
case 0:
{
if (workPhoneLen != 0)
{
cell.textLabel.text = NSLocalizedString(@"work :", @"workphone label");
cell.detailTextLabel.text = dispWorkphone;
} break;
case 1:
if (cellPhoneLen != 0)
{
cell.textLabel.text = NSLocalizedString(@"mobile :", @"cellphone label");
cell.detailTextLabel.text = dispCellphone;
}
}
}
}
else if (cellPhoneLen != 0)
{
cell.textLabel.text = NSLocalizedString(@"mobile :", @"cellphone label");
cell.detailTextLabel.text = dispCellphone;
}
} break;
case 2:
{
if (emailLen != 0)
{
cell.detailTextLabel.text = dispEMail;
}
} break;
case 3:
{
cell.detailTextLabel.lineBreakMode = UILineBreakModeWordWrap;
cell.detailTextLabel.numberOfLines = 3;
cell.detailTextLabel.text = address;
} break;
}
return cell;
}
edc1591。感謝你的方式從細胞工程中獲得價值完美。但是當我點擊一個數字時,它什麼都不做。我知道它不會打電話,因爲它不在實際的電話,但它應該給我一些錯誤的權利。以及它將如何知道如何發送短信,撥打電話或發送電子郵件或轉到地圖。我是否需要提供一些if語句或檢查什麼樣的價值被回收? – Hitz 2011-04-28 04:29:14
我相信tel://協議只適用於iPhone。無論它是否會在iPod/iPad中發生錯誤,我都不知道。我會找到和iPhone進行測試。我不知道如何檢測單元格中的數據類型。我不太瞭解你的代碼來幫助解決這個問題。 – edc1591 2011-04-28 14:48:06
在數據庫中,我的電話號碼存儲爲'1(234)567-8910'電子郵件的格式爲'[email protected]',地址顯示爲地址,城市,州,郵編和國家的組合。像'1 Infinite Loop,Cupertino,CA 95014 US'。 – Hitz 2011-04-28 16:35:23