2017-07-06 30 views
0

我一直試圖解析一個數組並將其分割爲單獨的字符串。在設置字符串時,我成功地通過單獨添加固定的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

回答

0

我設法通過改變didSelectRowAtIndexPath方法的字符串來解決我的問題。

而不是使用:

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

我用:

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

我決定嘗試使用數組,而不是結果字符串的,因爲它不會讓我從字符串提取信息。我會推薦以下@Larme的步驟,因爲他們肯定會讓我走向正確的方向。

如果有人試圖按照我的步驟,請確保您刪除valueForKey,因爲這是一個致命的錯誤。