如何将数据从collectionView发送到另一个视图(Objective-C)

时间:2019-07-20 12:13:32

标签: objective-c

<?php

// Function to print moving average
function movingAverage($win_numbers, $average_for)  
{ 
    foreach($win_numbers as $key=>$value){
      $win_number_consecutive_5 = array_slice($win_numbers, $key, 
$average_for);
  $win_averages[] = array_sum($win_number_consecutive_5) / $average_for;
}
return $win_averages;
} 

$existing = [];
$win_numbers = [];
for ($rnd=1;$rnd<=320;$rnd++)
{
$randoms[] = mt_rand(0,35);  // see this block for generating randoms
}

 echo "<b>Random Numbers:<br></b>";
 echo implode(' - ', $randoms).PHP_EOL;
 echo "<br><br>";

 $i = 0;
  foreach($randoms as $rnd){
  $i++; 
   if(in_array($rnd,$existing)){
   $win_numbers[] = $i;
   $i=1;
   $existing = [];
   }
   $existing[] = $rnd; 
 }

 echo "<b>Win Numbers:<br></b>";
 echo implode(' - ',$win_numbers);
 echo "<br><br>";

 echo "<b>Average Win Numbers In A Row Below 7:<br><br></b>";

 echo PHP_EOL;

  echo "<b>Moving Averages:<br></b>";
  $average_for = 5;
  echo implode(' - ',movingAverage($win_numbers, $average_for));
  echo "<br><br>";

   echo "<b>Chance The Downtrend Will Continue:<br><br></b>";

 ?>

我在NSLog上获得了真实数据,但无法将数据发送到CategoryItemViewController。 dataText变量始终为null。为什么?

2 个答案:

答案 0 :(得分:0)

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    _categoryModel = [[CategoryModel alloc] initWithCategoryName:self.titleee[indexPath.row]];
    _dataIndex = indexPath.row;
    self.data = self.titleee[indexPath.row];
    NSLog(@"Data: %@",self.data);
    [self passDataForward:indexPath.row];
}

-(void)passDataForward:(NSInteger)dataIndex {
    CategoryItemViewController *categoryVC = [[CategoryItemViewController alloc] init];
    categoryVC.dataText = self.titleee[dataIndex];
}

请尝试这个。

答案 1 :(得分:-1)

希望您已经在 CategoryItemViewController.h 文件中创建了一个属性,例如

@property NSString *dataText;

现在,您可以将数据作为如下所示的参数传递给方法,而不是全局引用所选索引,

[self passDataDorward:self.titleee[indexPath.row]];

现在如下更改方法

-(void)passDataDorward:(NSString* )dataText{ CategoryItemViewController *categoryVC = [[CategoryItemViewController alloc] init]; categoryVC.dataText = dataText; }

希望这可以解决您的问题。