2

DetailView内で前/次のボタンを作成する方法よりも(テーブルビューに戻って次のアイテムを押すことなく)、plistでUITableViewを使用してテーブルビューを作成しますか?

プログラム:

- (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;
}
4

1 に答える 1

0

データ配列と現在のインデックスを詳細ビュー コントローラーに渡します。表示する現在のレコードを選択するボタンにアクションを追加します。

于 2012-10-14T14:22:43.397 に答える