0

(在带有 Storyboards 的 XCode 4 中,适用于 iPhone 的应用程序)

我的 DetailView:一个填充了标签和 ImageViews 的 UIView,用于显示在 MainTableViewController 中选择单元格时通过 segue 接收到的详细信息。现在我在这个 UIView 上添加了一个 UIScrollView,因为我希望 Labels 和 ImageViews 显示在滚动视图中。

现在,当我运行应用程序时,DetailViewController 中唯一可见的是一个空白的 ScrollView。我从 TableView 传递的任何内容都没有显示,它没有得到 selectedObject。添加 UIScrollView 后,如何显示我的内容并能够使用 swipeDetectedLeft 滑动单元格?如果你能用我的代码做例子,我会很高兴。

DetailViewController.h:

@interface DetailViewController : UIViewController {
    IBOutlet UIScrollView *viewScroller; 
    //Added a ScrollView..
    }

@property (strong, nonatomic) NSArray *detailsDataSource; 
//Recieved from the TableView to know the order of the sorted TableView cells, cells populated with a mutable array from a plist of dictionaries)

@property int detailIndex; 
//To know which cell selected (for swiping throug cells)

@property (nonatomic, strong) NSString *selectedObject; 
//Content of selected cell from tableview (for swiping through cells)

@property (nonatomic, strong) IBOutlet UILabel *aLabel; 
@property (nonatomic, strong) IBOutlet UIImageView *anImageView; 
//to display content

DetailViewController.m:

#import "DetailViewController.h"

@interface DetailViewController ()

@end

@implementation DetailViewController

@synthesize aLabel,anImageView;
@synthesize selectedObject;

@synthesize detailsDataSource, detailIndex;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
    // Custom initialization
}
return self;
}


- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
}

- (void)viewDidLoad
{
[super viewDidLoad];

[viewScroller setScrollEnabled:YES];
[viewScroller setContentSize:CGSizeMake(320, 700)];

//A customized Label for NavigationBar    
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 480, 44)];
label.backgroundColor = [UIColor clearColor];
label.numberOfLines = 2;
label.font = [UIFont boldSystemFontOfSize: 14.0f];
label.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.5];
label.textAlignment = UITextAlignmentCenter;
label.textColor = [UIColor whiteColor];
label.text = [selectedObject valueForKey:@"Name"];
self.navigationItem.titleView = label;
[label release];


aLabel.text = [selectedObject valueForKey:@"A Label"];
anImageView.image = [UIImage imageNamed:[selectedWine valueForKey:@"An Image"]];

self.navigationController.navigationBar.translucent = YES;
self.wantsFullScreenLayout = YES;

UISwipeGestureRecognizer *leftGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeDetectedLeft:)];
leftGesture.direction = UISwipeGestureRecognizerDirectionLeft;
[self.view addGestureRecognizer:leftGesture];
}

- (void)swipeDetectedLeft:(UISwipeGestureRecognizer *)sender
{
if (detailIndex != [detailsDataSource count])
    detailIndex++;

aLabel.text = [[detailsDataSource objectAtIndex: detailIndex] valueForKey:@"A Label"];
//Here follows ImageView and NavigationbBar Label for the swipe..
}

编辑:

如果我设置 aLabel.text = @"Test" 那么它可以工作。所以 UIScrollView 没有从以下位置获取 selectedObject:

MainTableViewController.m:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {


if ([[segue identifier] isEqualToString:@"DetailSegue"]) {

    NSIndexPath *selectedRowIndex = [self.tableView indexPathForSelectedRow];
    DetailViewController *detailViewController = [segue destinationViewController];

    detailViewController.selectedObject = [sortedObjects objectAtIndex:selectedRowIndex.row];

    detailViewController.detailsDataSource = [[NSArray alloc]initWithArray:sortedObjects];
    detailViewController.detailIndex = selectedRowIndex.row;
}
}
4

1 回答 1

2

其实答案很简单:我只需要将 UIView 从情节提要的场景中移除,然后将 UIScrollView 直接放到 DetailViewController 场景中即可。

于 2012-07-19T21:15:13.197 回答