0

I am somewhat new to iOS, but am experienced in Android.

I have an app I am working on and it needs to populate a page with your "history" of past people you've interacted with, and it shows their picture, name, rating, and some other information.

This needs to populate in a vertical list, maybe a table? See the image below...

enter image description here

Now, in android, I would create a custom class with a layout that houses the picture, name, information, rating, and what not in one xml file, and in the activity I would call that class in a for loop, grabbing all the users and then programmatically it would add each view one after another, with their own unique user information until there is no more users to populate with.

How exactly can I do this in iOS and xcode? Do I need to make an XIB and add the picture, name, rating, and info place holders in that, and create a custom class for it that I would use to run in a for loop as well? I am a little stuck on how to do this with iOS.

Any help is much appreciated, and I can provide any additional information! Thanks :)

Jake Weso
  • 555
  • 1
  • 6
  • 14

3 Answers3

0

The first thing you have to do in switching from Android to iOS is to learn the terminology. Then you'll know what to search for on Google, SO, etc.

What's you're looking to do is create a UITableView.

Here is a link to a super basic 'how-to' to get you started with tableviews. http://www.appcoda.com/uitableview-tutorial-storyboard-xcode5/

Once you've got the basics down, you'll want to take that a step further with learning how to customize the UITableViewCell within your tableview, so you can accomplish the look you've detailed in the question. http://www.appcoda.com/customize-table-view-cells-for-uitableview/

I'm not sure I can help anymore than that at the moment. Jump in, learn tableviews, and start searching on OS to answer the million other questions you'll have a long the way.

Good luck!

Frankie
  • 11,508
  • 5
  • 53
  • 60
0

In iOS, you probably want to use a UITableView, with each row being a custom subclass of UITableViewCell. You can either create the layout for those cells in a separate XIB, or put the whole lot, tableView and "prototype" cells in a storyboard. You can achieve a lot without even subclassing, so fire up a dummy project in XCode and play (using one of Apple's templates gives you a good start). Enjoy.

pbasdf
  • 21,386
  • 4
  • 43
  • 75
0

What you probably want is to use a UITableView.

You don’t do the for-loop yourself. What you do is implement a set of delegate methods that the table view calls back to.

You can create your prototype cell in your XIB or Storyboard. When you add a Table View to the layout, you can then add a cell to that table view, and that cell will be your prototype. It looks like you only need one prototype cell, but you can create as many as you need. In Interface Builder you give the prototype cell a “reuse identifier”, which is just an arbitrary tag you use to refer to the prototype in your code. Your prototype cell can be your own subclass of UITableViewCell, or if you don’t need any custom code in it, you can just use UITableViewCell.

Then you implement several delegate methods. One is where you set the number of sections in the table view; it looks like you will only have on section.

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tv
{
    return 1;
}

Then you tell it how many items are in the table view. Assuming you have the objects you want to display in an array, you just return the length of the array.

- (NSInteger)tableView:(UITableView *)tv numberOfRowsInSection:(NSInteger)section
{
    return self.objects.count;
}

Then, for each item in the array, cellForRowAtIndexPath will be called. Make that method return the actual cell. You call dequeueReusableCellWithIdentifier to retrieve your prototype cell, using the reuse identifier you assigned in Interface Builder. Then use the corresponding object to set up the UI elements in your cell.

- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)i
{
    UITableViewCell *cell = [tv dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:i];

    Thingy *item = self.objects[i.row];
    cell.textLabel.text = item.name;

    return cell;
}

That should be enough to get you started with the documentation, now that you have the overview of what you need to implement.

Jeremy
  • 4,339
  • 2
  • 18
  • 12