A
A
Alexander Gomzyakov2013-09-13 06:18:45
Cocoa
Alexander Gomzyakov, 2013-09-13 06:18:45

Problem with segue transition in Storyboard?

There is a UITableViewController with a UISearchDisplayController that displays lists of certain products. In order for information to be presented in the same way both in the main table and in the lookup table, the GoodsCell cell was created (inherited from UITableViewCell). GoodsCell is created programmatically and has the following simple form:

@interface GoodsCell ()
{
  UIImageView *photoView;
  UILabel *titleLabel;
}

@end

@implementation GoodsCell

- (GoodsCell *)init {
  CGRect frame = CGRectMake(0.0f, 0.0f, 320.0f, 70.0f);

  self = [super initWithFrame:frame];
  if (self) {
    photoView = [[UIImageView alloc] initWithFrame:CGRectMake(10.0f, 10.0f, 50.0f, 50.0f)];
    [self addSubview:photoView];

    self.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

    titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(70.0f, 10.0f, 215.0f, 50.0f)];
    // задаём некоторые атрибуты метки
    [self addSubview:titleLabel];
  }
  
  return self;
}

- (void)setPhoto:(UIImage *)photo {
  photoView.image = photo;
}

- (void)setTitle:(NSString *)title {
  [titleLabel setText:title];
}

@end

In the Storyboard, a Seque was created from the GoodsViewController directly (responsible for displaying a list of goods) to the GoodsDetailViewController (detailed information about the product). The click is handled as follows:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
  UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
  [self performSegueWithIdentifier:@"goodsDetail" sender:tableView];
}

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
  if ([[segue identifier] isEqualToString:@"goodsDetail"])
  {
    GoodsDetailViewController *goodsDetailViewController = (GoodsDetailViewController *)[segue destinationViewController];
    
    if (sender == self.searchDisplayController.searchResultsTableView)
    {
      NSIndexPath *indexPath = [self.searchDisplayController.searchResultsTableView indexPathForSelectedRow];
      Goods *goods = [foundGoodsObjects objectAtIndex:indexPath.row];
      [goodsDetailViewController setGoods:goods];
    }
    else
    {
      NSIndexPath *indexPath = [goodsTable indexPathForSelectedRow];
      Goods *goods = [goodsObjects objectAtIndex:indexPath.row];
      [goodsDetailViewController setGoods:goods];
    }
  }
}

When you click on a cell, the application crashes with an error:
*** Assertion failure in -[GoodsCell layoutSublayersOfLayer:], /SourceCache/UIKit/UIKit-2372/UIView.m:5776
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Auto Layout still required after executing -layoutSubviews. GoodsCell's implementation of -layoutSubviews needs to call super.'

The code in the current version of the project was moved from another git branch, with a not very successful conflict merge. Elements in Storyboard and IBOutlets were added manually. In the original branch, everything works fine - the transition to the detailed view occurs, nothing falls.
I broke my head, what's the problem. Need help, dear habroznato!
PS I tried to place a fake cell in the table and seque from it - it doesn't help, the result is the same.

Answer the question

In order to leave comments, you need to log in

[[+comments_count]] answer(s)
I
IgorFedorchuk, 2013-09-13
@IgorFedorchuk

You can look at this topic here and also here

L
LIAL, 2013-09-13
@LIAL

So the error says what he wants: GoodsCell's implementation of -layoutSubviews needs to call super.
Judging by this, the cant is not in the code you provided, but where you fill the TableView with your GoodCell - there you need to kick the parent

A
Alexey Storozhev, 2013-09-15
@storoj

in my opinion it is not good to call initWithFrame in init, reload initWithFrame right away. setting the height of the cell here will do nothing, it will still be controlled by the table in heightForRowAtIndexPath:

A
Alexey Storozhev, 2013-09-15
@storoj

Segue can be pulled directly from the cells, then it will not be necessary to implement such didSelectRowForIndexPath

U
usgleb, 2013-10-20
@usgleb

Wow! How do you create cells? [[GoodsCell alloc] init]?

Z
Zoxaer, 2013-11-29
@Zoxaer

If you are using NSLayoutConstraint to arrange the titleLabel into cells, then you must specify titleLabel.translatesAutoresizingMaskIntoConstraints = NO.
In general, for all UIViews that are laid out through NSLayoutConstraint (this is AutoLayout), you must specify view.translatesAutoresizingMaskIntoConstraints = NO.
And if you use AutoLayout through InterfaceBuilder, then it automatically changes this flag.

A
Alexey Storozhev, 2013-12-24
@storoj

I didn’t delve into it carefully, but overloading init, and even with a call to initWithFrame, is not the best idea
, I’m not exactly sure, but it seems that if you overload it, then
in your viewController at the table you should do it
and then use
or even do xib for the cell as usual, there arrange everything, make constraints and use
UITableView registerNib:forCellReuseIdentifier:

Similar questions

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question