2011-09-08 105 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恤倒着穿出去。你基本上已經啓動了(已經初始化),並將數組的指針設置爲你的特色對象。 –

相關問題