2012-10-14 52 views
2

我使用UITableView與plist來製作tableview,而不是如何在DetailView中創建上/下一個按鈕(無需返回tableview並按下一個項目)?UITableView使用plist創建一個前面和下一個按鈕?

程序:

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

回答

0

通行證數據陣列和當前索引到詳細視圖控制器。將操作添加到將選擇當前記錄以放棄的按鈕。

+0

非常感謝!但我是Objective-C的初學者,能否爲這種情況展示實際的程序。 –

+0

對不起朋友,我不得不搬家。明天可以幫助你。這很容易,你可以試試。包含項目的數組,currentIndex屬性,2個按鈕操作(+/- currentIndex),還需要檢查數組邊界 – NeverBe

相關問題