Answer the question
In order to leave comments, you need to log in
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
- (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];
}
}
}
*** 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.'
Answer the question
In order to leave comments, you need to log in
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
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:
Segue can be pulled directly from the cells, then it will not be necessary to implement such didSelectRowForIndexPath
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.
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 useUITableView registerNib:forCellReuseIdentifier:
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question