ios - 如何从基于数据模型(NSobject)的 NSArray 访问对象?

标签 ios objective-c uitableview nsarray datamodel

我有一个数组,它在下面执行并组合了多个 QBUUser 用户。

2018-01-24 12:05:33.095197+0400 聊天[70177:6634702] 组合阵列(

  "
  [QBUUser]:
  ID:25957858
  created at:2017-04-04 11:06:17 +0000
  updated at:2017-12-18 06:03:52 +0000
  externalUserID:0
  blobID:0
  facebookID:(null)
  twitterID:(null)
  twitterDigitsID:(null)
  full name:rothessa balinario  sevilla
  email:rothessa.sevilla@aujan.com
  login:6395
  phone:3
  tags:(null)
  lastRequestAt:2017-12-18 06:06:22 +0000
  customData:default.png
  website:http://hr team coordinator",
    "
  [QBUUser]:
  ID:26229973
  created at:2017-04-11 13:00:53 +0000
  updated at:2018-01-24 08:04:12 +0000
  externalUserID:0
  blobID:0
  facebookID:(null)
  twitterID:(null)
  twitterDigitsID:(null)
  full name:dalila  isabelle   safir
  email:dalila.safir@aujan.com
  login:9937
  phone:2
  tags:(null)
  lastRequestAt:2018-01-24 08:04:12 +0000
  customData:default.png
  website:http://human resources director",
    "
  [QBUUser]:
  ID:26429684
  created at:2017-04-16 06:42:44 +0000
  updated at:2018-01-22 11:01:24 +0000
  externalUserID:0
  blobID:0
  facebookID:(null)
  twitterID:(null)
  twitterDigitsID:(null)
  full name:fawaz al  omran
  email:fawaz.alomran@aujan.com
  login:9129
  phone:3
  tags:(null)
  lastRequestAt:2018-01-22 11:01:24 +0000
  customData:default.png
  website:http://brand manager - vimto cordial",
    "
  [QBUUser]:
  ID:26472195
  created at:2017-04-17 06:24:44 +0000
  updated at:2018-01-23 08:22:06 +0000
  externalUserID:0
  blobID:0
  facebookID:(null)
  twitterID:(null)
  twitterDigitsID:(null)
  full name:ahmet  kursat  kaymaz
  email:kursat.kaymaz@aujan.com
  login:9625
  phone:3
  tags:(null)
  lastRequestAt:2018-01-23 08:22:06 +0000
  customData:default.png
  website:http://category manager",

所以我想访问全名并加载到我的tableview方法ex - user.fullname [indexpath.row] ..但我不知道访问所有用户并将其加载到我的 TableView 中的方法。

我尝试了以下方法并且没有 indexpath.row,因此它仅将最后一个用户加载到 tableview。
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return multiCombinedArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    //  UserTableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"contactUserCell" forIndexPath:indexPath];
    static NSString *cellIdentifier = @"UserTableViewCellIdentifier";
    ChatUserTableViewCell *chatUsersCell = (ChatUserTableViewCell *)[self.tableView dequeueReusableCellWithIdentifier:cellIdentifier];

    if(chatUsersCell == nil)
    {
        chatUsersCell = [[ChatUserTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }

  //  chatUsersCell.chatUserFullName.text = multiCombinedArray

    for(QBUUser *user in multiCombinedArray)
    {
        chatUsersCell.chatUserFullName.text = [NSString stringWithFormat:@"%@",user.fullName];

    }
  return chatUserCell;
}

请帮助我快速访问全名并将所有名称加载到表格 View 中。

最佳答案

您无需循环访问您的 multiCombinedArray , 使用 indexPath.row 访问就足够了,所以

替换这个

for(QBUUser *user in multiCombinedArray)
    {
        chatUsersCell.chatUserFullName.text = [NSString stringWithFormat:@"%@",user.fullName];

    }

通过这个
   QBUUser * user = multiCombinedArray[indexPath.row];
   chatUsersCell.chatUserFullName.text = [NSString stringWithFormat:@"%@",user.fullName];

关于ios - 如何从基于数据模型(NSobject)的 NSArray 访问对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48417928/

相关文章:

ios - 在 Swift 中带有下拉菜单的自定义 UITableViewCell

ios - 显示 UIMenuController 取消选择 UITableViewCell

objective-c - NSXMLParser 不释放分配?

ios - 如何在我的 iPod touch 上安装 iPhone 应用程序

iphone - 在 iPhone 中加载应用程序时出现问题

ios - 使用 NSURLSession 下载文件仅在 iPhone 充电时发生

ios - 添加图像时静态 TableView 崩溃

iphone - 分组的 UITableView 底部边框

ios - 从 FIRRemoteConfigValue 转换为不相关的类型 String 总是失败 : Firebase, Swift

ios - 有没有什么优雅的方法可以将 Hook 方法恢复到 iOS 上的原始实现?