简体   繁体   中英

Loading UIView with uitableview

Hello I want to load a UIView when you click on a line of uitableview. I did as it is this link: ViewController Segue Xamarin But is giving the following error in the printing, the Man.storyboard and also has the simulator. Below is the view code that has uitableview and also the code of UITableViewSource. I appreciate if anyone can help.

在此处输入图片说明

在此处输入图片说明

partial class ListaWodsFemininosViewController : BaseController2
{
    public ListaWodsFemininosViewController (IntPtr handle) : base (handle)
    {
    }

    public override void ViewDidLoad ()
    {
        base.ViewDidLoad ();

        DetalheWodViewController detalhe = (DetalheWodViewController)Storyboard.InstantiateViewController("detalhe");

        List<WodReferencia> Wods = new List<WodReferencia> ();

        WodReferencia ref0 = new WodReferencia {
            Nome        = "Amanda",
            Feminino    = "Three rounds, 9-7- and 5 reps, of:\n" +
                "Muscle-up 135 pound Squat snatch.",
            Masculino   = "Three rounds, 9-7- and 5 reps, of: " +
                "Muscle-up 135 pound Squat snatch."

        };
        Wods.Add (ref0);

        WodReferencia ref1 = new WodReferencia {
            Nome        = "Angie",
            Feminino    = "100 Pull-ups 100 Push-ups 100 Sit-ups 100 Squats.",
            Masculino   = "100 Pull-ups 100 Push-ups 100 Sit-ups 100 Squats."
        };
        Wods.Add (ref1);

        WodReferencia ref2 = new WodReferencia {
            Nome        = "Annie",
            Feminino    = "Double-unders Sit-ups 50-40-30-20 and 10 rep rounds.",
            Masculino   = "Double-unders Sit-ups 50-40-30-20 and 10 rep rounds."
        };
        Wods.Add (ref2);

        WodReferencia ref3 = new WodReferencia {
            Nome        = "Barbara",
            Feminino    = "20 Pull-ups 30 Push-ups 40 Sit-ups 50 Squats Rest precisely 3 minutes between each round. 5 rounds, time each round.",
            Masculino   = "20 Pull-ups 30 Push-ups 40 Sit-ups 50 Squats Rest precisely 3 minutes between each round. 5 rounds, time each round."
        };
        Wods.Add (ref3);

        WodReferencia ref4 = new WodReferencia {
            Nome        = "Chelsea",
            Feminino    = "5 Pull-ups 10 Push-ups 15 Squats Each minute on the minute for 30 minutes.",
            Masculino   = "5 Pull-ups 10 Push-ups 15 Squats Each minute on the minute for 30 minutes."
        };
        Wods.Add (ref4);

        WodReferencia ref5 = new WodReferencia {
            Nome        = "Christine",
            Feminino    = "3 rounds for time of: 500 m Row 12 BW Deadlift 21 Box Jumps.",
            Masculino   = "3 rounds for time of: 500 m Row 12 BW Deadlift 21 Box Jumps."
        };
        Wods.Add (ref5);

        WodReferencia ref6 = new WodReferencia {
            Nome        = "Cindy",
            Feminino    = "5 Pull-ups 10 Push-ups 15 Squats As many rounds as possible in 20 minutes.",
            Masculino   = "5 Pull-ups 10 Push-ups 15 Squats As many rounds as possible in 20 minutes."
        };
        Wods.Add (ref6);

        ...

        gridWods.Source = new FonteTabelaWodsFeminino (Wods,detalhe);
    }

    public override void PrepareForSegue (UIStoryboardSegue segue, NSObject sender)
    {
        if (segue.Identifier == "detalhe") {
            var detalhe = segue.DestinationViewController as DetalheWodViewController;
        }
    }
}

public class FonteTabelaWodsFeminino : UITableViewSource
{

    private List<WodReferencia> wodsFemininos; 
    DetalheWodViewController detLocal;
    private string cellIdentifier = "TableCell";

    public FonteTabelaWodsFeminino (List<WodReferencia> wodsF, DetalheWodViewController det)
    {
        wodsFemininos = wodsF;
        this.detLocal  = det;
    }

    public override nint RowsInSection (UITableView tableview, nint section)
    {
        if (wodsFemininos != null) {
            return wodsFemininos.Count;
        } else {
            return 0;
        }
    }

    public override UITableViewCell GetCell (UITableView tableView, Foundation.NSIndexPath indexPath)
    {
        UITableViewCell cell            = tableView.DequeueReusableCell (cellIdentifier); 
        if (cell == null)
            cell = new UITableViewCell (UITableViewCellStyle.Subtitle, cellIdentifier);

        cell.TextLabel.Lines            = 0;
        cell.TextLabel.SizeToFit ();
        cell.TextLabel.LineBreakMode    = UILineBreakMode.WordWrap;
        cell.DetailTextLabel.Text       = wodsFemininos [indexPath.Row].Masculino;
        cell.TextLabel.Text             = wodsFemininos [indexPath.Row].Nome;
        return cell;
    }

    public override void RowSelected (UITableView tableView, NSIndexPath indexPath)
    {
        detLocal.PerformSegue("detalhe", detLocal);
    }
}

Think you need to give your segue an Id like so:

在此处输入图片说明

Just noticed your using the Xamarin iOS designer so here is screenshot for that too ;)

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM