UITableView选定行加载新视图携带变量



我有一个UITableView在我的ViewController1。在选择时,它加载ViewController2,携带一个变量(我声明为"passseddata"),其中包含所选行的名称。在测试代码的可操作性时,我将"passseddata"分配给ViewController2上的一个标签,如下所示:

label.text = "passedData";

它工作得很好。列表在我的tableview在ViewController1有行加载从临时命名约定的数组:摘要、报告、细节等

所以这个想法是当"Summary"被选中时,它会加载ViewController2,然后加载另一个与SummaryViewController相关的子视图。在试图让ViewController2识别哪个视图控制器子加载,我这样做在-(void) viewDidLoad:

NSString *viewtoload = passedData;
    if (viewtoload == "Summary") {
        //Load summaryViewController
    }
    elseif (viewtoload == "Report") {
        //Load reportViewController
    }
    elseif (viewtoload == "Detail") {
        //Load detailViewController
    }

i got this error:

1. Implicit conversion of a non-objective-C pointer type 'char *' to 'NSString *' is disallowed with ARC.
2. Result of comparison against a string literal is unspecified (use strncmp instead)
3. Comparison of distinct pointer types ('NSString *' and 'char *')

我的问题是:

1)这是正确的方法还是有更好的方法?

2)我如何解决这个错误,我得到了上面?

3)加载另一个子视图的语法是什么?

提前感谢大家。

如果你想根据点击的单元格来加载不同的视图控制器你应该在

中这样做
//handle selections of cell in specified row and section of table view
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    //switch row
    switch(indexPath.row)
    {
        case:0
        {
            //Detail row
            Detail01 *viewController = [[Detail01 alloc] init];
            viewController.somePassedInData = theDataToPass;
            [self presentViewController:viewController animated:YES completion:nil];
            break;
        }
        case:1
        {
            //Report row
            Report01 *viewController = [[Report01 alloc] init];
            viewController.somePassedInData = theDataToPass;
            [self presentViewController:viewController animated:YES completion:nil];
            break;
        }
        case:2
        {
            //Summary row
            //Alloc and init VC here
            Summary01 *viewController = [[Summary01 alloc] init];
            viewController.somePassedInData = theDataToPass;
            [self presentViewController:viewController animated:YES completion:nil];
            break;
        }
        default:
        {
            break;
        }
    }
    //deselect table cell
    [_tableView deselectRowAtIndexPath:indexPath animated:YES];
}    

你可以在点击导航控制器

之前在VC中设置任何属性

使用正确的objective-c字符串字量@""代替""

最新更新