Created
December 18, 2016 20:03
-
-
Save jonathanpeppers/e142234d609f24e48045619845913aa4 to your computer and use it in GitHub Desktop.
TableSource for Packt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TableSource : UITableViewSource | |
{ | |
const string MyCellName = "MyCell"; | |
const string TheirCellName = "TheirCell"; | |
readonly MessageViewModel messageViewModel = | |
ServiceContainer.Resolve<MessageViewModel>(); | |
readonly ISettings settings = ServiceContainer.Resolve<ISettings>(); | |
public override nint RowsInSection( | |
UITableView tableview, nint section) | |
{ | |
return messageViewModel.Messages == null ? 0 : | |
messageViewModel.Messages.Length; | |
} | |
public override UITableViewCell GetCell( | |
UITableView tableView, NSIndexPath indexPath) | |
{ | |
var message = messageViewModel.Messages [indexPath.Row]; | |
bool isMyMessage = message.UserName == settings.User.Name; | |
var cell = (BaseMessageCell)tableView.DequeueReusableCell( | |
isMyMessage ? MyCellName : TheirCellName); | |
cell.TextLabel.Text = message.Text; | |
return cell; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment