Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/102.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

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
Ios 将图像加载到UIScrollView中_Ios_Xcode_Uiscrollview_Uiimageview - Fatal编程技术网

Ios 将图像加载到UIScrollView中

Ios 将图像加载到UIScrollView中,ios,xcode,uiscrollview,uiimageview,Ios,Xcode,Uiscrollview,Uiimageview,我希望有人能帮我,我不知道还能做什么。我有一个UIScrollView,它加载了一组44幅图像,然后允许用户翻阅它们。我的代码正在工作,然后突然停止了。我不知道我改变了什么,因此非常感谢您的帮助: 上一个视图是UITableView,它传递一个字符串以及所选单元格的名称。以下是ScrollView中的ViewDidLoad方法: - (void)viewDidLoad { [super viewDidLoad]; UIBarButtonItem *rightButton = [

我希望有人能帮我,我不知道还能做什么。我有一个UIScrollView,它加载了一组44幅图像,然后允许用户翻阅它们。我的代码正在工作,然后突然停止了。我不知道我改变了什么,因此非常感谢您的帮助:

上一个视图是UITableView,它传递一个字符串以及所选单元格的名称。以下是ScrollView中的ViewDidLoad方法:

- (void)viewDidLoad
{
    [super viewDidLoad];

    UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithTitle:@"Answer"
                                                                    style:UIBarButtonItemStyleBordered
                                                                   target:self
                                                                   action:@selector(answerPressed:)];

    self.navigationItem.rightBarButtonItem = rightButton;

    if([questionSetName isEqualToString:@"Limitations"]){

        [self limitationsView];
    }
}
以下是限制视图:

-(void)limitationsView{

    UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, -44, self.view.frame.size.width, self.view.frame.size.height)];

    scroll.pagingEnabled = YES;

    NSArray *unsortedArray = [[NSBundle mainBundle] pathsForResourcesOfType:@"png" inDirectory:@"Images/Limitations"];

    NSMutableArray *limitationImages = [[NSMutableArray alloc] init];

    for (int x = 0; x<[unsortedArray count]; x++) {

        NSString *fileName = [[unsortedArray objectAtIndex:x] lastPathComponent];

        [limitationImages insertObject:fileName atIndex:x];
    }

    NSArray *sortedArray = [limitationImages sortedArrayUsingFunction:finderSortWithLocal
                                                              context:(__bridge void *)([NSLocale currentLocale])];

    for(int i = 0; i< [sortedArray count]; i++){

        CGFloat xOrigin = i * self.view.bounds.size.width;

        UIImageView *limitationImageView = [[UIImageView alloc] initWithFrame:CGRectMake(xOrigin, 0, self.view.frame.size.width, self.view.frame.size.height)];;

        [limitationImageView setImage:[UIImage imageNamed:[sortedArray objectAtIndex:i]]];

        limitationImageView.contentMode = UIViewContentModeScaleAspectFit;

        [scroll addSubview:limitationImageView];

    }

    scroll.contentSize = CGSizeMake(self.view.frame.size.width * [sortedArray count], self.view.frame.size.height);

    [self.view addSubview:scroll];


}
-(无效)限制视图{
UIScrollView*scroll=[[UIScrollView alloc]initWithFrame:CGRectMake(0,-44,self.view.frame.size.width,self.view.frame.size.height)];
scroll.paginEnabled=是;
NSArray*unsortedArray=[[NSBundle mainBundle]路径ForResourceSoftType:@“png”目录:@“图像/限制”];
NSMutableArray*limitationImages=[[NSMutableArray alloc]init];
对于(intx=0;x我建议使用

NSLog(@"image:%@",[UIImage imageNamed:[limitationsArray objectAtIndex:i]]); 

若要查看映像在该点是否为空。如果是这种情况,则表示存储在该数组中的字符串存在问题,即它们与映像的实际名称不相同

我建议使用NSLog(@“image:%@,[UIImage ImageName:[limitationsArray objectAtIndex:i]);以查看图像在该点是否为空。如果是这种情况,则您存储在该数组中的字符串存在问题,即,它们与图像的实际名称不完全相同谢谢-您是正确的,日志显示为零,问题与我使用的路径有关。一旦我更新到正确的路径ev一切都很好-干杯