2017-07-06 9 views
0

私は配列を解析して別の文字列に分割しようとしていました。私は文字列を設定するときに固定objectAtIndexを個別に追加することによって、この作業を成功させることができました。テーブルビューから個々の文字列に配列を解析する - Objective-C

例:しかし

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

、私は試してみて、どんなobjectAtIndex文字列を使用してのtableView didSelectRowAtIndexPath内の文字列を設定し、常にnullを返します。 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

は、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を削除して致命的なエラーが発生していることを確認してください。

関連する問題