在我的应用程序中,在 splitViewController 的左侧 tableview 中,列出了我的联系人。单击联系人时,我想将其联系人 ID 传递给 detailViewController。并在 detailViewController 的 viewDidLoad 方法中调用一个方法,该方法会访问 webservice 并提取该联系人 ID 的联系人详细信息并将它们显示在 detailViewController 中。这就是逻辑。但是我在点击tableView时调用detailViewController有问题。一旦我单击 tableview,DetailViewController 的 ViewDidLoad 方法就不会被调用(我在 detailPage 的 ViewDidLoad 中有 NSlog,但未打印)
我附上了 rootViewController 的 didSelectRowAtIndexPath 方法的代码。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Navigation logic may go here. Create and push another view controller.
if([serachBar.text isEqualToString:@""] || serachBar.text == nil)
{
NSString *ContactIdStr=[NSString stringWithFormat:@"%@",[[objectsForCharacters objectForKey:[arrayOfCharacters objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row]];
NSArray *afterSeprate = [[NSArray alloc]init];
afterSeprate = [ContactIdStr componentsSeparatedByString:@"+"];
//NSString *cellText = [afterSeprate objectAtIndex:0];
NSString *detailText = [afterSeprate objectAtIndex:1];
appdelegate.contactId=[NSString stringWithString:detailText];
}
else
{
serachBar.text = nil;
NSString *ContactIdStr=[NSString stringWithFormat:@"%@",[searchArray objectAtIndex:indexPath.row]];
NSArray *afterSeprate = [[NSArray alloc]init];
afterSeprate = [ContactIdStr componentsSeparatedByString:@"+"];
//NSString *cellText = [afterSeprate objectAtIndex:0];
NSString *detailText = [afterSeprate objectAtIndex:1];
appdelegate.contactId=[NSString stringWithString:detailText];
}
// Pass the selected object to the new view controller.
detailViewController = [[DetailView_iPad alloc] initWithNibName:@"DetailView_iPad" bundle:nil];
[detailViewController.navigationController pushViewController:detailViewController animated:YES];
//self.detailViewController.navigationController
[ContactTableview deselectRowAtIndexPath:indexPath animated:YES];
}