单击tableview的单元格,加载nib / xib / view

时间:2013-02-18 20:37:58

标签: iphone ios objective-c xamarin.ios

如何从我的tableview中选择一行时打开一个nib / xib / view ...下面是我的代码

public class TableViewDelegate : UITableViewDelegate 
{
    private List list;

    public TableViewDelegate(List<string> list)
    {
        this.list = list;
    }    

    public override void RowSelected (UITableView tableView, NSIndexPath indexPath)
    {
        Console.WriteLine("TableViewDelegate.RowSelected: Label={0}",list[indexPath.Row]);
    }
}

2 个答案:

答案 0 :(得分:0)

您应该使用didSelectRowAtIndexPath方法:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NewViewController *myViewController = [[NewViewController alloc] initWithNibName:@"NewViewController" bundle:nil];
[self presentModalViewController:myViewController animated:YES];
    }

答案 1 :(得分:0)

只需将新视图控制器添加为子视图。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NewViewController *myViewController = [[NewViewController alloc] initWithNibName:@"NewViewController" bundle:nil];
    [self.view addSubView:myViewController];
}