2010-04-09 19 views
0

我有一個詳細視圖,包含一個表視圖與幾行數據。我可以很好地填充行,並從父視圖來回移動到子視圖。此詳細視圖應該允許用戶選擇單個值,在單元格中放置複選標記附件,然後返回到父視圖(其中所選值將成爲調用詳細視圖的單元格的cell.textLabel.text屬性)。這一切現在工作。如何管理單選(排他)列表?

但是,當用戶點擊父視圖中的單元格以返回到詳細視圖(更改它們的選擇)時,我的複選標記消失了,我不能爲我的生活弄清楚如何使其保留。

這裏是我的cellForRowAtIndexPath:方法:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString *CellIdentifier = @"Cell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease]; 
     } 

    NSString *labelText = [[phones objectAtIndex:indexPath.row] valueForKey:@"phoneNumberLabel"]; 
    cell.textLabel.text = labelText; 
    NSString *currentLabel = [ruleBuilder.tableView cellForRowAtIndexPath:selectedIndexPath].textLabel.text; 
    if (labelText == currentLabel) { 
     cell.accessoryType = UITableViewCellAccessoryCheckmark; 
     } 

    NSString *detailText = [[phones objectAtIndex:indexPath.row] valueForKey:@"phoneNumber"]; 
    cell.detailTextLabel.text = detailText; 
    return cell; } 

我已經簽出蘋果的示例代碼查看錶獨家列表管理編程指南,但片段似乎不完整,我無法找到相關的蘋果示例代碼中的代碼。這似乎不應該那麼難。

回答

0

哎呦......問題是在這條線:

if (labelText == currentLabel) { 

比較兩個字符串就像下面這樣:

if ([labelText isEqualToString:currentLabel]) { 

這解決了這個問題,立竿見影。