表视图使用自定义单元格文件以及如何使用segue

时间:2012-03-10 13:47:18

标签: objective-c storyboard

我用户Master-Detail创建了一个项目。在MasterViewController,表格单元格我使用MasterCell.hMasterCell.m来构建我的自定义单元格,因此我的代码是:

- (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;
}

我想点击单元格然后按DetailViewController,所以我的stroyboard是使用origin creat segue,但是它不起作用,我认为segue不是我的MasterCell,我试图改变故事板单元格自定义类,并没有成功。我该怎么办?感谢。

1 个答案:

答案 0 :(得分:7)

在你的故事板中你应该不是从单元格创建segue,而是从整个UITableViewController创建segue并设置一些标识符,例如" MySegue"而风格是" Push"。

然后在tableViewController中添加

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

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

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

    //do your stuff

    }
 }
相关问题