来自我的应用程序的编码 detailView,它有一个分组表视图。如果单击电子邮件,我希望应用程序拨打选定的电话号码或发送文本或发送电子邮件,如果选择了地址,则转到谷歌地图。这是我的 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;
}