Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.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 UICollectionView标题在_Ios_Objective C - Fatal编程技术网

Ios UICollectionView标题在

Ios UICollectionView标题在,ios,objective-c,Ios,Objective C,在我的应用程序中,我基于数据集构建了一个集合视图。当我执行清理安装时,所有标题显示正确。重新打开应用程序后,第一个标题将消失。在viewWillAppeard方法中调用reloadData并不能解决问题 我的代码: #import "ChapterViewController.h" #import "XMLParser.h" #import "ChapterStore.h" #import "Chapter.h" #import "Section.h" #import "Word.h"

在我的应用程序中,我基于数据集构建了一个集合视图。当我执行清理安装时,所有标题显示正确。重新打开应用程序后,第一个标题将消失。在viewWillAppeard方法中调用reloadData并不能解决问题

我的代码:

    #import "ChapterViewController.h"
#import "XMLParser.h"
#import "ChapterStore.h"
#import "Chapter.h"
#import "Section.h"
#import "Word.h"
#import "ChapterViewCell.h"

@interface ChapterViewController ()
@property (nonatomic, strong) IBOutlet UICollectionView *collectionView;
@property (nonatomic, strong) NSArray *dataArray;

@end

@implementation ChapterViewController

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

        [[self navigationItem] setTitle:@"Chapters"];
        self.navigationController.navigationBar.translucent = NO;
        NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];

        if ( ![userDefaults valueForKey:@"version"] )
        {
            [[ChapterStore sharedStore] doParse];

            [self spaceTrimmer:[ChapterStore sharedStore]];


            // Adding version number to NSUserDefaults for first version:
            [userDefaults setFloat:[[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"] floatValue] forKey:@"version"];
        }


        if ([[NSUserDefaults standardUserDefaults] floatForKey:@"version"] == [[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"] floatValue] )
        {
            /// Same Version so dont run the function
        }
        else
        {
            // Call Your Function;

            // Update version number to NSUserDefaults for other versions:
            [userDefaults setFloat:[[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"] floatValue] forKey:@"version"];
        }

    }
    return self;
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:YES];
    [[self collectionView] reloadData];    
}

- (NSInteger)numberOfChapters {
    return [[[ChapterStore sharedStore] allChapters] count];
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    NSMutableArray *chapters = [[NSMutableArray alloc] init];
    for (int i = 0; i < [self numberOfChapters]; i++) {
        [chapters addObject:[[[ChapterStore sharedStore] allChapters] objectAtIndex:i]];
    }
    if ([self respondsToSelector:@selector(edgesForExtendedLayout)])
        self.edgesForExtendedLayout = UIRectEdgeNone;

    self.dataArray = chapters;

    UINib *cellNib = [UINib nibWithNibName:@"ChapterViewCell" bundle:nil];
    [self.collectionView registerNib:cellNib forCellWithReuseIdentifier:@"cvCell"];
    [self.collectionView registerNib:[UINib nibWithNibName:@"ChapterViewHeader" bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"cvHeader"];


    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    [flowLayout setItemSize:CGSizeMake(159, 159)];
    [flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical];
    [flowLayout setMinimumInteritemSpacing:2];
    [flowLayout setMinimumLineSpacing:2];
    [flowLayout setHeaderReferenceSize:CGSizeMake(0, 50)];


    [self.collectionView setCollectionViewLayout:flowLayout];

}


- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {

    UICollectionReusableView *header = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"cvHeader" forIndexPath:indexPath];

    Chapter *data = [self.dataArray objectAtIndex:indexPath.section];

    NSString *chapterName = [data CHAPTER_NAME];

    UILabel *titleLabel = (UILabel *)[header viewWithTag:99];

    [titleLabel setText:chapterName];

    return header;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {

    Chapter *data = [self.dataArray objectAtIndex:indexPath.section];

    Section *section = [[data sections]objectAtIndex:indexPath.row];

    NSString *cellData = [section SECTION_NAME];

    static NSString *cellIdentifier = @"cvCell";

    ChapterViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
    int i = [indexPath indexAtPosition:0] + 1;
    int j = [indexPath indexAtPosition:1] + 1;

    NSString *imageName = [NSString stringWithFormat:@"c%ds%d.jpg", i,j];

    UIImage *image = [UIImage imageNamed:imageName];

    [cell setController:self];
    [cell setCollectionView:collectionView];

    [[cell sectionLabel] setText:cellData];

    [[cell imageView]setImage:image];

    return cell;

}

-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return [self.dataArray count];
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    Chapter *sectionArray = [self.dataArray objectAtIndex:section];
    return [[sectionArray sections] count];
}
#导入“ChapterViewController.h”
#导入“XMLParser.h”
#导入“ChapterStore.h”
#导入“第h章”
#导入“第h节”
#导入“Word.h”
#导入“ChapterViewCell.h”
@接口章节ViewController()
@属性(非原子,强)IBUICollectionView*collectionView;
@属性(非原子,强)NSArray*数据数组;
@结束
@实现章节视图控制器
-(id)initWithNibName:(NSString*)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil
{
self=[super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
如果(自我){
[[self-navigationItem]设置标题:@“章节”];
self.navigationController.navigationBar.translucent=否;
NSUserDefaults*userDefaults=[NSUserDefaults standardUserDefaults];
如果(![userDefaults valueForKey:@“版本”])
{
[[ChapterStore sharedStore]doParse];
[self spaceTrimmer:[ChapterStore sharedStore]];
//为第一个版本的NSUserDefault添加版本号:
[userDefaults setFloat:[[[[NSBundle mainBundle]infoDictionary]objectForKey:@“CbundLeverVersion”]floatValue]forKey:@“version”];
}
如果([[NSUserDefaults standardUserDefaults]floatForKey:@“版本”]==[[[[NSBundle mainBundle]信息字典]objectForKey:@“CbundLeverVersion”]floatValue])
{
///相同版本,因此不要运行该函数
}
其他的
{
//调用你的函数;
//将版本号更新为其他版本的NSUserDefault:
[userDefaults setFloat:[[[[NSBundle mainBundle]infoDictionary]objectForKey:@“CbundLeverVersion”]floatValue]forKey:@“version”];
}
}
回归自我;
}
-(无效)视图将显示:(BOOL)动画{
[超级视图将显示:是];
[[self collectionView]重新加载数据];
}
-(NSInteger)章节数{
返回[[[ChapterStore sharedStore]所有章节]计数];
}
-(无效)viewDidLoad
{
[超级视图下载];
NSMutableArray*章=[[NSMutableArray alloc]init];
对于(int i=0;i<[self numberOfChapters];i++){
[章节添加对象:[[ChapterStore sharedStore]所有章节]对象索引:i]];
}
if([自响应选择器:@selector(edgesForExtendedLayout)])
self.edgesForExtendedLayout=UIRectEdgeNone;
self.dataArray=章节;
UINib*cellNib=[UINib-nibWithNibName:@“ChapterViewCell”bundle:nil];
[self.collectionView注册表项nb:cellNib forCellWithReuseIdentifier:@“cvCell”];
[self.collectionView注册表项nb:[UINib nibWithNibName:@“ChapterViewHeader”bundle:nil]对于种类为:UICollectionElementKindSectionHeader with ReuseIdentifier:@“cvHeader”];
UICollectionViewFlowLayout*flowLayout=[[UICollectionViewFlowLayout alloc]init];
[flowLayout setItemSize:CGSizeMake(159159)];
[flowLayout设置滚动方向:UICollectionViewScrollDirection垂直];
[flowLayout setMinimumInteritemSpacing:2];
[流程布局设置最小行间距:2];
[flowLayout setHeaderReferenceSize:CGSizeMake(0,50)];
[self.collectionView setCollectionViewLayout:flowLayout];
}
-(UICollectionReusableView*)collectionView:(UICollectionView*)collectionView视图用于种类的SupplementElementOfKind:(NSString*)种类索引路径:(NSIndexPath*)索引路径{
UICollectionReusableView*header=[collectionView出列ReusableSupplementaryViewofKind:kind with ReuseIdentifier:@“cvHeader”forIndexPath:indexPath];
第*章数据=[self.dataArray objectAtIndex:indexPath.section];
NSString*chapterName=[数据章节名称];
UILabel*标题标签=(UILabel*)[标题视图带标记:99];
[标题标签setText:chapterName];
返回头;
}
-(UICollectionViewCell*)collectionView:(UICollectionView*)collectionView cellForItemAtIndexPath:(NSIndexPath*)indexPath{
第*章数据=[self.dataArray objectAtIndex:indexPath.section];
Section*Section=[[datasections]objectAtIndex:indexath.row];
NSString*cellData=[section_NAME];
静态NSString*cellIdentifier=@“cvCell”;
ChapterViewCell*cell=[collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier for indexPath:indexPath];
int i=[indexPath indexateposition:0]+1;
int j=[index:1]+1;
NSString*imageName=[NSString stringWithFormat:@“c%ds%d.jpg”,i,j];
UIImage*image=[UIImage imageName:imageName];
[小区控制器:自身];
[单元格设置collectionView:collectionView];
[[cell sectionLabel]setText:cellData];
[[cell imageView]设置图像:图像];
返回单元;
}
-(NSInteger)collectionView中的节数:(UICollectionView*)collectionView
{
返回[self.dataArray count];
}
-(NSInteger)collectionView:(UICollectionView*)collectionView项目编号截面:(NSInteger)截面
{
第*章sectionArray=[self.dataArray objectAtIndex:section];
返回[[sectionArray sections]计数];
}

这似乎是缓存或IOS 7升级问题。我完全卸载了应用程序,重新启动了xcode和模拟器,问题现在消失了。

这似乎是缓存或IOS 7升级问题。我完全卸载了应用程序,重新启动了xcode和模拟器,现在问题已经解决了