首先,執行賽格瑞原諒我的英語,因爲我是法國人:-)與原型細胞
我是一個iOS的開發初學者,我嘗試使用主詳細視圖用了XCode 4.4。
我想要什麼:
我的主視圖包含的UITableView與原型細胞。當我點擊我的單元格時,我想看到詳細視圖。
這是我的代碼:
MasterViewController.m
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
// Configure the cell...
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
NSDictionary* instrument = [Instruments objectAtIndex:indexPath.row];
NSLog(@"instrument: %@",instrument);
NSString* status = [instrument objectForKey:@"status"];
NSLog(@"status: %@",status);
NSString* imageName = [NSString stringWithFormat:@"%@48.png", [status lowercaseString]];
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
imgView.image = [UIImage imageNamed:imageName];
cell.imageView.image = imgView.image;
// Set up the cell...
NSString *cellValue = [instrument objectForKey:@"id"];
cell.textLabel.text = cellValue;
return cell;
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"masterToDetails"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
NSDictionary* instrumentDetails = [Instruments objectAtIndex:indexPath.row];
[[segue destinationViewController] setDetailItem:instrumentDetails];
}
}
當然我有一個賽格瑞在我的故事板我的原型細胞鏈接到與「masterToDetails」爲標識符詳細視圖。
當我點擊我的主表的原型細胞,prepareForSegue不叫。 爲什麼?
然後,當我試圖迫使賽格瑞電話與:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self performSegueWithIdentifier:@"masterToDetails" sender:[self.tableView cellForRowAtIndexPath:indexPath]];
}
我有以下錯誤:NSInvalidArgumentException,原因是:接收器有沒有賽格瑞與標識符masterToDetails
但它在我的故事板的存在!
也許我用MasterDetail是錯誤的或者也許這是一個愚蠢的錯誤,從我的方式...
告訴我,如果你想從我的應用程序等細節。
此外,請檢查故事板中單元的重用標識符。根據你的代碼,它應該是「Cell」 – Darren
FWIW,這個簡明但詳細的答案比在操作頂部過於詳細的重複鏈接的價值高出100倍 – kfmfe04