質問

I'm trying to send data to a tab bar controller in didSelectRowAtIndexPath method. When I send array with data first time it works ok, but when data of array is changed and I send it again array of second tab bar stays the same as it was first time. Can you please help me to understand why is that? code:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

if(cell.accessoryType == UITableViewCellAccessoryNone) {
    cell.accessoryType = UITableViewCellAccessoryCheckmark;
    [_arrayToPass addObject:[_data objectAtIndex:indexPath.row]];
}
else {

    cell.accessoryType = UITableViewCellAccessoryNone;
    [_arrayToPass removeObject:[_ingridients objectAtIndex:indexPath.row]];

}

NextTableViewController *nextController = (NextTableViewController *)    [self.tabBarController.viewControllers objectAtIndex:1];

nextController.items = _arrayToPass;
}

and then in nextController I want to populate tableView with content of "items" array. in

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:  (NSIndexPath *)indexPath
 {
    static NSString *simpleTableIdentifier = @"Cell";
    UITableViewCell *cell = [tableView     dequeueReusableCellWithIdentifier:simpleTableIdentifier];

  if (cell == nil) {
      cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault   reuseIdentifier:simpleTableIdentifier];
}

    cell.textLabel.text = [_items objectAtIndex:indexPath.row];

 return cell;
}  
役に立ちましたか?

解決

Your question is vague and unclear. You mention that it works the first time but not the second, but then never indicate what that means. You post code that sets a property in your NextTableViewController, but don't give any indication of what you do with that property. Post the method from NextTableViewController that does something with the items property.

If I had to guess, I would guess that you're processing it in your viewDidLoad method, which gets called once and only once when the VC is first displayed.

You should add code in your NextTableViewController's viewWillAppear:animated method that does whatever it needs to do with your items property.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top