Note that there are some explanatory texts on larger screens.

plurals
  1. POPush a ViewController from au CustomCell
    text
    copied!<p>I've created a custom cell named "CustomPreviCell" (its the name of the NIb and the Identifier of the cell in this NIB). My customCell contains 6 labels and an imageView. The .m file corresponding to this cell is following : </p> <pre><code>@interface CustomPreviCell : UITableViewCell @property (weak, nonatomic) IBOutlet UIImageView *iconImageView; @property (weak, nonatomic) IBOutlet UILabel *weatherLabel; @property (weak, nonatomic) IBOutlet UILabel *detailOneLabel; @property (weak, nonatomic) IBOutlet UILabel *detailTwoLabel; @property (weak, nonatomic) IBOutlet UILabel *dayNumberLabel; @property (weak, nonatomic) IBOutlet UILabel *dayTextLabel; @property (weak, nonatomic) IBOutlet UILabel *monthLabel; @end </code></pre> <p>And implementation : </p> <pre><code>#import "CustomPreviCell.h" @implementation CustomPreviCell @synthesize iconImageView; @synthesize weatherLabel; @synthesize detailOneLabel; @synthesize detailTwoLabel; @synthesize dayNumberLabel; @synthesize dayTextLabel; @synthesize monthLabel; - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { // Initialization code } return self; } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; } @end </code></pre> <p>Now, i want display this cell in a tableView (of course!). So in my storyboard, i have created a new UITableView with one CustomCell prototype, and i refered the view to my class "SinglePreviViewController" which extends "UITableViewController". I implemented classic methods for tableView (numberOfRowsInSection: etc ...). </p> <p>In the method "cellForRowAtIndexPath", i want to create, initialize and display my custom cells , so i writed :</p> <pre><code>NSString *simpleTableIdentifier = @"CustomCellPrevi"; CustomPreviCell *cell = (CustomPreviCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier]; NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"CustomCellPrevi" owner:self options:nil]; for (id currentObject in topLevelObjects){ if ([currentObject isKindOfClass:[CustomPreviCell class]]){ cell = (CustomPreviCell *)currentObject; NSString * iconName = [self loadIcon:indexPath.row]; [cell.iconImageView setImage:[UIImage imageNamed:iconName]]; cell.detailOneLabel.text = [[NSString alloc] initWithFormat:@"%@°C - %@mm",[descriptor.temperature objectAtIndex:indexPath.row], [descriptor.precipitations objectAtIndex:indexPath.row]]; cell.detailTwoLabel.text = [[NSString alloc] initWithFormat:@"%@ (%@) km/h - %@hPa",[descriptor.vent objectAtIndex:indexPath.row],[descriptor.rafales objectAtIndex:indexPath.row], [descriptor.pression objectAtIndex:indexPath.row]]; cell.weatherLabel.text = [descriptor.temps objectAtIndex:indexPath.row]; NSDictionary * date = [self getDateComponentsFromXMLDate:[descriptor.date objectAtIndex:indexPath.row]]; if([[date valueForKey:@"dayNumber"] intValue] %2 == 0) [cell.contentView setBackgroundColor:[UIColor colorWithWhite:1 alpha:0.0]]; else [cell.contentView setBackgroundColor:[UIColor colorWithWhite:1 alpha:0.15]]; cell.dayTextLabel.text = [date valueForKey:@"dayText"]; cell.dayNumberLabel.text = [[NSString alloc] initWithFormat:@"%@ %@",[date valueForKey:@"dayNumber"],[date valueForKey:@"month"]]; cell.monthLabel.text = [date valueForKey:@"hour"]; } } return cell; </code></pre> <p>Let's launch my app : it works correctly ! My tableView contains my CustomPreviCells and display the content correctly. But... When i want to push a new viewController from these cells, its not working. I've connected my customCell (from the cell in my TableView in the storyboard) to the new viewcontroller (named DetailPreviViewcontroller), but it does nothing. My customCell is just selected.</p> <p>Please help :)</p> <p><strong>EDIT 1:</strong></p> <pre><code> -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { NSLog(@"Hey !"); if([segue.identifier isEqualToString:@"propertiesSegue"]) { NSLog(@"Hello"); SingleVillePropertiesViewController * destinationController = [segue destinationViewController]; [destinationController setVille:ville]; } else if([segue.identifier isEqualToString:@"detailPreviSegue"]) { DetailPreviViewController * destController = [segue destinationViewController]; [[self navigationController] pushViewController:destController animated:YES]; //TODO : set previDescriptor to my destController but it's not important // for this problem. } } </code></pre> <p><strong>EDIT 2 :</strong> Ok i don't have yet the solution to this problem, but i get rid of it by doing this :</p> <p>1/ Create a new nib for the View controller you want to push (not in the storyboard)</p> <p>2/ Set it the Class of your ViewController (in my case DetailPreviViewController) and the View of FilesOwner to the NIB View</p> <p>3/ Push the view from the method "didSelectRowAtPath" with the navigationController. </p> <p>I don't like this way to proceed, but it's for now, the only one which works...</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload