-1

我的 ViewController1 上有一个 UITableView。选择后它会加载 ViewController2,携带一个变量(我声明为“passedData”) ,该变量也包含所选行的名称。在测试代​​码的可行性时,我将“passedData”分配给 ViewController2 上的标签,如下所示:

label.text = "passedData";

它工作得很好。ViewController1 中我的表视图中的列表具有从具有临时命名约定的数组加载的行:摘要、报告、详细信息等。

因此,想法是选择“摘要”时,它将加载ViewController2,然后加载与SumberViewController相关的另一个子视图。为了让 ViewController2 识别要子加载的视图控制器,我在-(void) viewDidLoad:

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

我收到了这个错误:

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) 加载另一个子视图的语法是什么?

我提前感谢大家。

4

2 回答 2

1

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

//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 中设置任何属性

于 2013-03-22T16:24:17.927 回答
0

使用正确的objective-c字符串文字@""而不是""

于 2013-03-22T09:21:25.667 回答