user10917327
user10917327

Reputation:

populate table with to informations

I wanna put arrayVariable1 on the top and the second below.

I use the command:

            public override UITableViewCell GetCell (UITableView tableView, NSIndexPath indexPath)
        {
            UITableViewCell cell = tableView.DequeueReusableCell (cellID);

            if (cell == null) {
                cell = new UITableViewCell (UITableViewCellStyle.Subtitle, cellID);
            }

            cell.TextLabel.Text = ArrayVariable1;
            cell.TextLabel.Text = ArrayVariable2;

            return cell;
        }

But If I run it the variable1 doesn't appear, just the 2.

Upvotes: 0

Views: 40

Answers (4)

Jason
Jason

Reputation: 89082

A UITableViewCell of style UITableViewCellStyle.Subtitle has two different label properties. TextLabel is the upper label, and DetailTextLabel is the lower label

        cell.TextLabel.Text = ArrayVariable1;
        cell.DetailTextLabel.Text = ArrayVariable2;

Upvotes: 0

Wizkid
Wizkid

Reputation: 1035

You are overridding your TextLabel with ArrayVariable2. You set it with cell.TextLabel.Text = ArrayVariable1 then override it with cell.TextLabel.Text = ArrayVariable2. If you want to pack the data from the two array variables into a label (or better a UITextView), then you could do something like:

cell.TextLabel.Text = [NSString stringWithFormat:@"%@\n%@", ArrayVariable1, ArrayVariable2];

You will need to ensure that your label is set to multiple lines (i.e. 2 lines)

Upvotes: 0

Robert Lawson
Robert Lawson

Reputation: 83

Have a look at http://developer.xamarin.com/guides/ios/user_interface/tables/part_3_-_customizing_a_table's_appearance/

For different table types and using Titles, Subtitles etc I think this is what you might need, if not you can always create your own cell type.

Upvotes: 0

Frank
Frank

Reputation: 733

You're overwriting yourself in the second assignment to cell.TextLabel.Text

cell.TextLabel.Text = ArrayVariable1;
cell.TextLabel.Text = ArrayVariable2;  <-- this overwrites the line above this.

A very simple solution...

cell.TextLabel.Text = string.Format("{0} {1}", ArrayVariable1, ArrayVariable2);

But if you really want more than just a concatenation you'll have to create a custom layout for your cells and inflate that.

Upvotes: 2

Related Questions