将数据从一个视图推送到另一个视图

时间:2011-09-08 14:47:12

标签: objective-c ios uiviewcontroller

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

Promo 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];
    }

1 个答案:

答案 0 :(得分:0)

这可能是这一行:

Featured*featured = [self.featuredArray init];

这在许多方面都是错误的。

将此设为社区维基,因为我没有时间撰写完整的答案。