2011-09-08 99 views
0

我有一个NSSet中保存的促销表格列表,我将其加载到数组中以便在单元格上显示标题/名称。但是,我想使用didselectrow方法将选定的促销推送到单个促销页面。我制作了promo.featuredArray = self.featuredArray,但它似乎没有传递数据。我的代码如下。将数据从一个视图推送到另一个

促销list.m

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    NSString *CellIdentifier = @"CellIdentifier"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) 
    { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease]; 
    } 
    Featured*featured = [self.featuredArray objectAtIndex:indexPath.row]; 
    cell.textLabel.text = featured.details; 
    cell.textLabel.textColor = [UIColor whiteColor]; 
    cell.detailTextLabel.text = self.place.name; 
    return cell; 

} 
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

    Promo * promo= [[Promo alloc] initWithNibName:@"Promo" bundle:nil]; 
    //Featured*featured = [self.featuredArray objectAtIndex:indexPath.row]; 
    promo.featuredArray = self.featuredArray; 
    [self.navigationController pushViewController:promo animated:YES]; 
    [promo release]; 
    //[featured release]; 
} 

Promo.m

@synthesize featuredArray, featured = __featured; 

    - (void)viewDidLoad 
    { 

     self.clearImage = [UIImage imageNamed:@"fav_icon.png"]; 
     self.clearImagePressed = [UIImage imageNamed:@"fav_icon_sel.png"]; 
     Featured*featured = [self.featuredArray init]; 
     self.name.text = [NSString stringWithFormat:@"%@", __featured.name]; 
     self.time.text = [NSString stringWithFormat:@"%@", __featured.time]; 
     // self.description.text = [NSString stringWithFormat:@"%@", __featured.description]; 
     self.placeName.text = [NSString stringWithFormat:@"%@", __featured.Place]; 

     [super viewDidLoad]; 


     if([__featured.imageURL hasPrefix:@"http"]) 
     { 
      [self getImageForPlace]; 
     } 
    // else 
    // { 
    //  [self refreshImage]; 
    // } 
    //  
     self.title = @"Promotion"; 

     UIColor *background = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"background_texture.png"]]; 
     self.view.backgroundColor = background; 
     [background release]; 
     [featured release]; 
    } 
+0

你想传递给其他视图的对象是什么? – lifemoveson

+0

哇这是什么:'精选*特色= [self.featuredArray init];' –

+0

应该养成使用道具的习惯。 –

回答

0

这也可能是这一行:

Featured*featured = [self.featuredArray init]; 

这是错误的在许多方面。

使这个社区维基,因为我没有时间写一个完整的答案。

+0

我不明白这个以前的答案,因为我只是新的堆叠流。我已经尝试在int中推送数组的位置,并使用它从数组中提取数据:Featured * featured = [self.featuredArray objectAtIndex:self.position]; self.name.text = [NSString stringWithFormat:@“%@”,__featured.name]; self.time.text = [NSString stringWithFormat:@“%@”,__featured.time]; // self.description.text = [NSString stringWithFormat:@“%@”,__featured.description]; self.placeName.text = [NSString stringWithFormat:@“%@”,__featured.Place]; – Bradley

+0

迈克是对的,这就像是在同一时间穿着一件T恤倒着穿出去。你基本上已经启动了(已经初始化),并将数组的指针设置为你的特色对象。 –

相关问题