Table view uses customized cell file and how to use segue
I User-Master-Part has created a project. On a MasterViewController
table cell I am using MasterCell.h
and MasterCell.m
to create 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 that I want to click on a cell and click DetailViewController
, so my street board uses the original segue file, but that didn't work, I think the segue is not mine MasterCell
, and I tried to change the collapsible cell of the custom class and it was not successful. How should I do it? Thank.
In storyboard you have to create segue not from cell but from whole UITableViewController and set some id like "MySegue" and style "Push".
Then in your TableViewController you must 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
}
}