Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

table view use customized cell file and how ot use segue

I user Master-Detail created a project. On the MasterViewController, the table cell i use a MasterCell.h and MasterCell.m to build my customized cell, so my code is:

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

    cell = [[MasterCell alloc] initWithFrame:CGRectZero];
    NSString  *value = [[myContacts objectAtIndex:indexPath.row] valueForKey:@"Name"];
    cell.nameContentLabel.text = [NSString stringWithFormat:@"%@", value];

    value = [[myContacts objectAtIndex:indexPath.row] valueForKey:@"Tele"];
    cell.teleContentLabel.text=[NSString stringWithFormat:@"%@", value];

    value = [[myContacts objectAtIndex:indexPath.row] valueForKey:@"Image"];
    cell.myImageView.image = [[UIImage alloc] initWithContentsOfFile:value];

    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    return cell;
}

And whan i want click the cell and push the DetailViewController, so my stroyboard is use the origin creat segue, but it didn't work, i think the segue is not my MasterCell, and i had try to change the storyboard cell custom Class, and it was't not success.How do I do? Thanks.

like image 985
lighter Avatar asked Nov 27 '25 10:11

lighter


1 Answers

In your storyboard you should create segue not from cell, but from entire UITableViewController and set some identifier, for example "MySegue" and style is "Push".

Then in your tableViewController you should add

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
   {
       [self performSegueWithIdentifier:@"MySegue" sender:self];
   }

and

 -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{

if([segue.identifier isEqualToString:@"MySegue"]){

    //do your stuff

    }
 }
like image 102
sergey.tyan Avatar answered Nov 29 '25 00:11

sergey.tyan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!