从表视图解析数组到单个字符串 - Objective-C

从表视图解析数组到单个字符串 - Objective-C

问题描述:

我一直试图解析一个数组并将其分割为单独的字符串。在设置字符串时,我成功地通过单独添加固定的objectAtIndex来成功完成这项工作。从表视图解析数组到单个字符串 - Objective-C

例子:

NSString *weightString = [[[results valueForKey:@"Endurance"] objectAtIndex:7]objectAtIndex:2]; 

然而,当我尝试和使用任何objectAtIndex字符串始终返回null在的tableView didSelectRowAtIndexPath设置字符串。我需要能够使用objectAtIndex:indexPath.row点击tableView行。我无法弄清楚我出错的地方。随意请求更多的代码或查询。

查询:

PFQuery *arrayQuery = [PFQuery queryWithClassName:@"Exercises"]; 
[arrayQuery selectKeys:@[@"Endurance"]]; 
[arrayQuery orderByAscending:@"ExerciseName"]; 
[arrayQuery findObjectsInBackgroundWithBlock:^(NSArray *results, NSError *error) { 
if (!error) { self.arrayResults = [results valueForKey:@"Endurance"]; 

的cellForRowAtIndexPath:

- (TableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
static NSString *CellIdentifier = @"list"; 
TableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

UILabel *cellTitle; 
cell.cellTitle.text = [[browseAllArray objectAtIndex: indexPath.row] objectForKey:@"ExerciseName"]; 

if (cell == nil) { 
    cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    cell = [[TableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 

    //Exercise Bar Label 
    cellTitle = [[UILabel alloc] initWithFrame:CGRectMake(80, 20, 220, 60)]; 
    cellTitle.font = [UIFont fontWithName:@"ethnocentric" size:14]; 
    cellTitle.textColor = [UIColor blackColor]; 
    cellTitle.numberOfLines = 2; 
    cellTitle.textAlignment = NSTextAlignmentCenter; 

    cell.cellTitle.text = [[browseAllArray objectAtIndex: indexPath.row] objectForKey:@"ExerciseName"]; 
    [self.tableView reloadData]; 
} 
cellTitle.text = [[browseAllArray objectAtIndex:indexPath.row]objectForKey:@"ExerciseName"]; 
return cell; 
+0

share cellForRowAtIndex方法。 –

+0

显示'result'和'tableView:cellForRowAtIndexPath:' – Larme

+0

我的cellForRowAtIndexPath方法只包含设计单元的代码。我试图解析信息从我的数据库相应的相关细胞。你还需要它吗?如果是的话,我会发送它。 – HJDavies

我设法通过改变didSelectRowAtIndexPath方法的字符串来解决我的问题。

而不是使用:

NSString *weightString = [[[results valueForKey:@"Endurance"] objectAtIndex:indexPath.row]objectAtIndex:2]; 

我用:

NSString *weightString = [[arrayResults objectAtIndex:indexPath.row] objectAtIndex:2]; 

我决定尝试使用数组,而不是结果字符串的,因为它不会让我从字符串提取信息。我会推荐以下@Larme的步骤,因为他们肯定会让我走向正确的方向。

如果有人试图按照我的步骤,请确保您删除valueForKey,因为这是一个致命的错误。