图片不显示使用iCarousel [英] picture does not show up using iCarousel

查看:454
本文介绍了图片不显示使用iCarousel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在故事板中使用MultiCarousel,我收到错误,无法在转盘中显示图像。有代码的问题吗?我从viewfromItemAtIndex中收到错误说

预期方法体

预期':'

预期标识符或(

预期的标识符或(

无关的大括号(})

如果您想查看特定的部分,请随时询问更多代码。 p>

I am using MultiCarousel in a storyboard and I am getting errors and can not display the image in the carousel. Is there a problem with the code??I am getting errors from viewfromItemAtIndex saying
expected method body
expected':'
expected identifier or (
expected identifier or (
extraneous closing brace ("}")
Please feel free to ask for more code if you want to see a specific part.

#import "iCarouselExampleViewController.h"


@interface iCarouselExampleViewController ()

@property (nonatomic, retain) NSMutableArray *items1;
@property (nonatomic, retain) NSMutableArray *items2;

@end


@implementation iCarouselExampleViewController

@synthesize carousel1;
@synthesize carousel2;
@synthesize items1;
@synthesize items2;
- (void)awakeFromNib
{
    //set up data sources
    self.items1 = [NSMutableArray array];
    for (int i = 0; i < 100; i++)
    {
        [items1 addObject:[NSNumber numberWithInt:i]];
    }

    self.items2 = [NSMutableArray array];
    for (int i = 65; i < 65 + 58; i++)
    {
        [items2 addObject:[NSString stringWithFormat:@"%c", i]];
    }
}

- (void)dealloc
{
    //it's a good idea to set these to nil here to avoid
    //sending messages to a deallocated viewcontroller
    carousel1.delegate = self;
    carousel1.dataSource = self;
    carousel2.delegate = self;
    carousel2.dataSource = self;


}

#pragma mark -
#pragma mark View lifecycle

-(void)viewDidLoad
{
    [super viewDidLoad];

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSFileManager *fileManager  = [NSFileManager defaultManager];

    //configure carousel1
    NSString *fPath = [documentsDirectory stringByAppendingPathComponent:@"Tops"];
    NSArray *directoryContent = [fileManager directoryContentsAtPath: fPath];
    imageArray1 = [directoryContent mutableCopy];

    //configure carousel2
    fPath = [documentsDirectory stringByAppendingPathComponent:@"Bottoms"];
    directoryContent = [fileManager directoryContentsAtPath:fPath];
    imageArray2 = [directoryContent mutableCopy];

    carousel1.type = iCarouselTypeLinear;
    carousel2.type = iCarouselTypeLinear;
}

- (void)viewDidUnload
{
    [super viewDidUnload];

    //free up memory by releasing subviews
    self.carousel1 = nil;
    self.carousel2 = nil;
}

#pragma mark -
#pragma mark iCarousel methods

- (NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel
{
    //return the total number of items in the carousel
    if (carousel == carousel1)
    {
        return [imageArray1 count];
    }
    else
    {
        return [imageArray2 count];
    }
}

- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view

if (view == nil)
{
    view = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 200.0f, 200.0f)];

    UIImage *image;
    if (carousel == carousel1)
    {
        image  = [UIImage imageWithContentsOfFile:[imageArray1 objectAtIndex:index]];
        ((UIImageView *)view).image = image;
    }
    else
    {
        image  = [UIImage imageWithContentsOfFile:[imageArray2 objectAtIndex:index]];
        ((UIImageView *)view).image = image;
    }
    return view;
}
else {
    UIImage *image;
    if (carousel == carousel1)
    {
        image  = [UIImage imageWithContentsOfFile:[imageArray1 objectAtIndex:index]];
        ((UIImageView *)view).image = image;
    }
    else
    {
        image  = [UIImage imageWithContentsOfFile:[imageArray2 objectAtIndex:index]];
        ((UIImageView *)view).image = image;
    }
}


return view;
}


推荐答案

您在方法开始时错过了第一个括号。将来,Xcode将指向一个至少靠近错误的位置,您可以将其用作分析代码的起点。始终确保计算和平衡开和括号括号,括号和括号。

You were actually really close. You were missing the very first brace in the beginning of the method. In the future, Xcode will point you to a location at least near the error which you can use as a starting point to analyze your code. Always make sure to count and balance opening and closing braces, brackets, and parens.

- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view
{ // <--- This brace was missing!!
    if (view == nil)
    {
        view = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 200.0f, 200.0f)];

        UIImage *image;
        if (carousel == carousel1)
        {
            image  = [UIImage imageWithContentsOfFile:[imageArray1 objectAtIndex:index]];
            ((UIImageView *)view).image = image;
        }
        else
        {
            image  = [UIImage imageWithContentsOfFile:[imageArray2 objectAtIndex:index]];
            ((UIImageView *)view).image = image;
        }
        return view;
    }
    else {
        UIImage *image;
        if (carousel == carousel1)
        {
            image  = [UIImage imageWithContentsOfFile:[imageArray1 objectAtIndex:index]];
            ((UIImageView *)view).image = image;
        }
        else
        {
            image  = [UIImage imageWithContentsOfFile:[imageArray2 objectAtIndex:index]];
            ((UIImageView *)view).image = image;
        }
    }
    return view;
}

这篇关于图片不显示使用iCarousel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆