UITableView使用plist制作上一个和下一个按钮?

时间:2012-10-14 14:13:25

标签: iphone objective-c ios xcode ios5

我使用带有plist的UITableView制作一个tableview,而不是如何在DetailView中制作一个pervious / next按钮(不返回tableview并按下一项)?

该计划:

- (void)viewDidLoad
{
    [super viewDidLoad];
    NSMutableDictionary *labelDict = [[[NSMutableDictionary alloc]initWithContentsOfFile:[[[NSBundle mainBundle]bundlePath]stringByAppendingPathComponent:@"myData.plist"]] retain];
    cellImages = [[NSMutableArray alloc ] initWithArray:[labelDict objectForKey:@"image"]];
    cellTitles = [[NSMutableArray alloc] initWithArray:[labelDict objectForKey:@"title"]];
    cellSubTitles = [[NSMutableArray alloc] initWithArray:[labelDict objectForKey:@"subtitle"]];

    NSLog(@"%@", [[[NSBundle mainBundle] bundlePath]stringByAppendingPathComponent:@"myData.plist"]);

}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }

    // Configure the cell.

    cell.textLabel.text = [cellTitles objectAtIndex:indexPath.row];
    cell.detailTextLabel.text = [cellSubTitles objectAtIndex:indexPath.row];
    cell.imageView.image = [UIImage imageNamed:[cellImages objectAtIndex:indexPath.row]];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (!self.detailViewController) {
        self.detailViewController = [[[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil] autorelease];
    }

    [self.navigationController pushViewController:self.detailViewController animated:YES];
    self.detailViewController.detailImage.image = [UIImage imageNamed:[cellImages objectAtIndex:indexPath.row]];
    self.detailViewController.detailDescriptionLabel.text = [cellTitles objectAtIndex:indexPath.row];
    self.detailViewController.subTitle.text = [cellSubTitles objectAtIndex:indexPath.row];
    self.detailViewController.title = nil;
}

1 个答案:

答案 0 :(得分:0)

将数据数组和当前索引传递给详细视图控制器。将操作添加到将选择当前记录的按钮,以便取消付款。