我有一个UITableViewController
的联系人,当点击联系人时,我想从tableviewcontroller执行一个segue到实际的控制器。
这是我在-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
运行的代码:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// A lot of code, but it's basically saying: dependent of the section and whether you're searching or not, store the name and number you've selected.
number = [[NSMutableArray alloc]init];
if(indexPath.section == 0 && [self.usersWithNamesAndNumbers count] > 0){
if (self.searchDisplayController.isActive) {
index = [[self.searchDisplayController searchResultsTableView] indexPathForSelectedRow];
name = [[self.searchedUsersWithNamesAndNumbers allKeys] objectAtIndex:index.row];
number = [[self.searchedUsersWithNamesAndNumbers allValues] objectAtIndex:index.row];
} else {
index = [self.tableView indexPathForSelectedRow];
name = [[self.usersWithNamesAndNumbers allKeys] objectAtIndex:index.row];
number = [[self.usersWithNamesAndNumbers allValues] objectAtIndex:index.row];
}
} else {
if (self.searchDisplayController.isActive) {
index = [[self.searchDisplayController searchResultsTableView] indexPathForSelectedRow];
name = [[self.searchedContactNamesWithNumbers allKeys] objectAtIndex:index.row];
number = [[self.searchedContactNamesWithNumbers allValues] objectAtIndex:index.row];
} else {
index = [self.tableView indexPathForSelectedRow];
name = [[self.contactNamesWithNumbers allKeys] objectAtIndex:index.row];
number = [[self.contactNamesWithNumbers allValues] objectAtIndex:index.row];
}
}
[self performSegueWithIdentifier:@"moveToView" sender:self];
[tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
我也在prepareForSegue
方法中获得了一些代码:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([[segue identifier] isEqualToString:@"moveToView"]){
[[segue destinationViewController] setDidComeFromContacts:YES];
[[segue destinationViewController] setNameLabelContents:[NSString stringWithFormat:@"%@,", name]];
[[segue destinationViewController] setPhoneNumberLabelContents:number];
[[segue destinationViewController] setText:@"Segue text"];
[[segue destinationViewController] setCardId:@"EDf8oCCol2"];
}
}
处理此代码大约需要2-3秒。我还有两个其他的segue到同一个VC,那些长约1s,但仍然1-2s。这可能与destinationViewController
内的设置有关,还是在segue之前的设置?
非常感谢
答案 0 :(得分:0)
问题是由于目标视图控制器的initWithCoder方法中的长时间运行操作。将该代码移动到viewDidAppear中,以及viewDidLoad中依赖于initWitCoder中该代码结果的任何代码。这应该允许segue快速完成。最终,如果可能的话,您将需要尝试解决缓慢运行方法的问题。