Domanda

I have a static UITableview and am trying to segue to a modal view. I can't segue directly from the cell in storyboard as there is times when I would like the segue not to be invoked depending of some application logic. So I have hooked the segue up to the TableViewController and given it an identifier in storyBoard.In the TableViewController I then call the method below.

            - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
//Perform segue when first row in first section is touched
if(indexPath.section == 0){
    if(indexPath.row == 0){
        [self performSegueWithIdentifier:@"view1" sender:self.view];
    }}}

for some reason when the cell is tapped the modal view is really slow to appear. I have added NSLogs to the modal views viewDidLoad and viewDidAppear methods, The viewDidLoad is called instantly but viewDidAppear is slow.This seems to only happen when the cell is tapped for the first time after the tableView has loaded. It seems to be something to do with the didSelectRowAtIndex method as I have tried calling the performSegueWithIdentifier from an IBAction triggered from a button on the cell and it works great. Another point to mention if I uncheck the animates checkBox on the segue it works instantly. If anyone could help I would be most grateful.

È stato utile?

Soluzione

you can segue directly from cell in storyboard. There is another delegate method which can use for control segue action

- (BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender {

        [super shouldPerformSegueWithIdentifier:identifier sender:sender];

        if ([identifier isEqualToString:@"SegueIdentifier"]) {

            NSIndexPath *indexPath = [self.tableView indexPathForCell:sender];

            if (0 == indexPath.row) {
               if (0 == indexPath.row) {
                  return YES;
                }
            }
        }
        return NO;
  }

Altri suggerimenti

It seems this is a threading issue. Simply wrapping the call to performSegueWithIdentifier with a dispatch to the main thread. Works like butter!

dispatch_async(dispatch_get_main_queue(), {
    self.performSegueWithIdentifier("SegueName", sender:self)
})

Try this because sender should be a controller object

(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
 //Perform segue when first row in first section is touched
    if(indexPath.section == 0){
        if(indexPath.row == 0){
           [self performSegueWithIdentifier:@"view1" sender:self];
    }
   }
 }

I had this same exact problem. I haven't tested extensively but it seems to happen in iOS 8.1 and not in iOS 7.1.2. Oddly, the delay was even longer the second time I performed the unwind segue. (eg: Tap a button to present a UITableViewController, tap a close button to unwind, re-open it, re-close it - slow!)

Were you passing anything into sender: when you presented your tableViewController? I was passing self like so:

[self performSegueWithIdentifier:@"TableViewSegue" sender:self];

...but I found that passing nil instead makes the unwind delay almost go away. Sometimes it's still there, but only for about 0.5s on an iPhone 6. Such a weird issue. I also took out sender:self in my unwind command, just in case.

After doing some more testing, about 1 in 5 times it unwinds with a really horrible delay... about 4-5 seconds! Tapping the row a second time seems to actually make the unwind fire right away. But wow, this bug is pretty nasty. We should file bug reports on it: https://bugreport.apple.com/

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top