Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone I';如果已将UIScrollView添加到UIView(我的详细信息视图),现在如何显示内容?_Iphone_Xcode_Uiview_Uiscrollview - Fatal编程技术网

Iphone I';如果已将UIScrollView添加到UIView(我的详细信息视图),现在如何显示内容?

Iphone I';如果已将UIScrollView添加到UIView(我的详细信息视图),现在如何显示内容?,iphone,xcode,uiview,uiscrollview,Iphone,Xcode,Uiview,Uiscrollview,(在带有故事板的XCode 4中,iPhone应用程序) My DetailView(我的详细视图):一个UIView,其中填充了标签和图像视图,用于显示在MainTableViewController中选择单元格时通过序列接收到的详细信息。现在,我在这个UIView上添加了一个UIScrollView,因为我希望标签和图像视图显示在滚动视图中 当我运行应用程序时,DetailViewController中唯一可见的是一个空白的滚动视图。没有显示我从TableView传递的任何内容,它没有获取s

(在带有故事板的XCode 4中,iPhone应用程序)

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

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

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..
}
- (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;
}
}
编辑:

如果我设置了aLabel.text=@“Test”,那么它就工作了。因此,UIScrollView无法从以下位置获取selectedObject:

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

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

将UITableView放置到UIScrollView中是非常不鼓励的。由于UITableView继承自UIScrollView,因此如果将UITableView放在UIScrollView中,将出现未定义/意外的行为。@Scott ScrollView中没有TableView。DetailViewController是一个带有滚动视图的常规UIView。这是关于在DetailView中填充标签和图像视图的值(并控制SwipedTectedLeft方法)。这些值从UITableViewController通过segue传递,以填充DetailViewController.h中的属性。抱歉,误读了。也许我只是不明白你的问题,但我看到你的标签和图像视图是不正确的。它们是否真的连接到故事板中的标签和图像视图?如果是,它们是否在滚动视图中,而不是在滚动视图下?如果它们没有连接到IB中,那么我认为您的问题是您从未将标签和图像添加为滚动视图的子视图。@Scott插座连接到故事板中滚动视图中的标签。如果在情节提要中添加一个标签“label”,而没有任何属性连接到此标签,则该标签将显示在应用程序中。连接的标签不显示,因此问题可能与.h中的属性有关,或者可能与设置了labeltext的viewdidload中的属性有关?但在某些地方存在错误连接..如果更改
aLabel.text=[selectedObject valueForKey:@“a Label”]
aLabel.text=@“测试”
,只是为了确保
[selectedObject valueForKey:@“A Label”]
没有返回nil或空字符串。