0

我有一个表格视图,右侧有一个详细标签。我已经为我的应用程序委托中的一个变量分配了一个值,一切似乎都运行良好。当我单击一行时,我想为我的详细信息屏幕获取此值。我想要得到的值将放在下面的值@“Test”中。此值当前在每行右侧的详细信息中显示为字符串“Yes”或“No”。

didSelectRowAtIndexPath

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];

NSMutableArray *sectionArray = [self.arrayOfSections objectAtIndex:indexPath.section];

appDelegate.selectedSetting = [[NSString alloc] initWithFormat:@"Select value: %@ for %@, in section: %@", @"Test", [sectionArray objectAtIndex:indexPath.row], [self tableView:tableView titleForHeaderInSection:indexPath.section]];

[tableView deselectRowAtIndexPath:indexPath animated:YES];

SettingsViewController *settings = [[SettingsViewController alloc] initWithNibName:@"Settings" bundle:[NSBundle mainBundle]];

[self.navigationController pushViewController:settings animated:YES];
}

cellForRowAtIndex

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

UITableViewCell *result = nil;

if ([tableView isEqual:self.myTableView]){

    static NSString *CellIdentifier = @"CellIdentifier";

    result = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (result == nil){

        result = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
    }

    NSMutableArray *sectionArray = [self.arrayOfSections objectAtIndex:indexPath.section];

    result.textLabel.text = [sectionArray objectAtIndex:indexPath.row];

    NSString *res = (NSString *)result.textLabel.text;

    AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];

    if ([[self tableView:tableView titleForHeaderInSection:indexPath.section] isEqualToString:@"XYZ"]) {

        if ([res isEqualToString:@"ABC"]) {

            result.detailTextLabel.text = appDelegate.my_important_value;                
        } 
    }

    appDelegate.selected_value = result.detailTextLabel.text;

    result.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}

return result;
}
4

0 回答 0