I have created an app, in which i have a tableview. I want to move the view in certain conditions so I have changed the constraints, its working fine but when i tried to change the constraints again, the view is not moved.
My code as follows:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UINib *nib = [UINib nibWithNibName:@"GoalDetailsCustomCardCell" bundle:nil];
[goalDetailsTableView registerNib:nib forCellReuseIdentifier:@"CardCell"];
GoalDetailsTableViewCell *cell = [goalDetailsTableView dequeueReusableCellWithIdentifier:@"CardCell"];
if(cell == nil)
{
cell = [goalDetailsTableView dequeueReusableCellWithIdentifier:@"CardCell"];
}
if([self.swipedRowArray containsObject:indexPath])
{
NSLog(@"%f", cell.cardDetails.frame.origin.x);
NSLog(@"%f", cell.cardDetails.frame.size.width);
NSLog(@"%f", cell.cardDetails.frame.size.height);
cell.cardDetails.translatesAutoresizingMaskIntoConstraints = NO;
NSDictionary *contentDictionary = @{@"cardDetails":cell.cardDetails, @"actionReminderCard":cell.actionCardReminder};
[cell.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-(-314)-[cardDetails]" options:0 metrics:nil views:contentDictionary]];
[cell.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-8-[actionReminderCard]" options:0 metrics:nil views:contentDictionary]];
NSLog(@"%f", cell.cardDetails.frame.size.width);
NSLog(@"%f", cell.cardDetails.frame.size.height);
}
else
{
NSLog(@"%f", cell.cardDetails.frame.origin.x);
NSLog(@"%f", cell.cardDetails.frame.size.width);
NSLog(@"%f", cell.cardDetails.frame.size.height);
cell.cardDetails.translatesAutoresizingMaskIntoConstraints = NO;
NSDictionary *contentDictionary = @{@"cardDetails":cell.cardDetails, @"actionReminderCard":cell.actionCardReminder};
[cell.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-8-[cardDetails]" options:0 metrics:nil views:contentDictionary]];
[cell.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-330-[actionReminderCard]" options:0 metrics:nil views:contentDictionary]];
NSLog(@"%f", cell.cardDetails.frame.size.width);
NSLog(@"%f", cell.cardDetails.frame.size.height);
}
In the above code, if part is working perfectly, when it comes to else i tried to change the constraints to default constraints as set in the xib but it is not working. It shows the view as same as I changed the constraints before.
Thanks in advance.
Aucun commentaire:
Enregistrer un commentaire