Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/38.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 UITableView在滚动时损坏_Iphone_Objective C_Uitableview_Nsmutablearray - Fatal编程技术网

Iphone UITableView在滚动时损坏

Iphone UITableView在滚动时损坏,iphone,objective-c,uitableview,nsmutablearray,Iphone,Objective C,Uitableview,Nsmutablearray,我正在尝试获取UITableView以显示数组中包含的项。 此数组包含在HX_ParkingSearch类中 我有一个对这个类的引用,该类包含app delegate类中的数组,以使视图能够访问它。 问题是我在tableview中得到了一页正确显示的结果 但当我尝试向下滚动时,在尝试访问数组中的下一项时会发生异常。 结果是,当我向下滚动时,cellForRowAtIndexPath方法启动, 数组中的项目无效,似乎已被释放,但我不知道在哪里 他们被释放了 有人有什么想法吗?因为这真的让我头疼 非

我正在尝试获取UITableView以显示数组中包含的项。 此数组包含在HX_ParkingSearch类中

我有一个对这个类的引用,该类包含app delegate类中的数组,以使视图能够访问它。 问题是我在tableview中得到了一页正确显示的结果 但当我尝试向下滚动时,在尝试访问数组中的下一项时会发生异常。 结果是,当我向下滚动时,cellForRowAtIndexPath方法启动, 数组中的项目无效,似乎已被释放,但我不知道在哪里 他们被释放了

有人有什么想法吗?因为这真的让我头疼

非常感谢,, 克里斯

//自定义表格视图单元格的外观

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";
    HX_ParkingLocation *location;
    bookingApp2AppDelegate *del  = (bookingApp2AppDelegate *) [[UIApplication sharedApplication] delegate];   


    NSMutableArray* array = [del.parkingSearch locations];

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }


    location = (HX_ParkingLocation*) [array objectAtIndex: [indexPath row] ];




    return cell;
}




#import <Foundation/Foundation.h>


@interface HX_ParkingLocation : NSObject
{


    NSString *name;


}


@property(retain,nonatomic) NSString* name;


/*
 Initialises this Location instance by passing in the name and code of the location and the URL of the webapi product endpoint.
 The URL is used to find available products at this location.
 */
-(id) initWithName: (NSString*) n;

@end


#import <Foundation/Foundation.h>


@interface HX_ParkingSearch : NSObject 
{
    NSMutableArray* locations;

}
@property (retain) NSMutableArray* locations;


-(BOOL) loadLocations;

@end


#import "HX_ParkingSearch.h"
#import "HX_Parking_Location.h"



@implementation HX_ParkingSearch
@synthesize locations;

//Finds the locations
-(BOOL) loadLocations
{   


    [locations release];
    //Create array to hold locations
    locations = [[NSMutableArray alloc] initWithCapacity:30];

    //Loop through all returned locations
    for(int i=0;i<15;i++)
    {
        //Get location name
        NSString* n = [NSString stringWithFormat:@"Item #%i",i ];



        //Create location instance, which retrieves availability and product information and stores the information in location object.
        HX_ParkingLocation* location = [[HX_ParkingLocation alloc] initWithName:n];
        //add to array
        [locations addObject:location];




    }


    return YES;

}



@end



#import <UIKit/UIKit.h>
#import "HX_ParkingSearch.h"

@interface bookingApp2AppDelegate : NSObject <UIApplicationDelegate> {

    UIWindow *window;
    UINavigationController *navigationController;
     HX_ParkingSearch *parkingSearch;

}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
@property (retain) HX_ParkingSearch *parkingSearch;


@end

@implementation bookingApp2AppDelegate

@synthesize window;
@synthesize navigationController;
@synthesize parkingSearch;


- (void)applicationDidFinishLaunching:(UIApplication *)application 
{


    //Create new parking search instance by specifying the endpoint urls
    HX_ParkingSearch* search = [[HX_ParkingSearch alloc] init];
    [search loadLocations];

    parkingSearch = search;
    //NSLog(@"Search Retain count = %i" ,[search retainCount]);




    [window addSubview:[navigationController view]];
    //[window addSubview:[navigationController initWithNibName:@"VC_Locations" bundle:[NSBundle mainBundle]]];
    [window makeKeyAndVisible];

}

是否有理由在loadLocations中以30个容量初始化阵列,但只插入15个项?

此方法对数据源有何作用

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
而且:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

tableview可能只是试图获取一个超出位置界限的索引

没有理由我只是在玩。如果不是存储HX_ParkingLocation,而是在数组中存储NSString类型的对象,则问题似乎不会发生!你知道为什么会这样吗?干杯,克里希非常感谢你的回复。昨晚很晚才解决的!显然,在没有休息的情况下拔头发的时间太长了。原来我没有保留对HXParkingLocation内容的引用,所以所有内容都被发布了!对HX标记位置的实际参考是好的,我显然得到了错误的结果!无论如何,干杯,非常感谢。克里斯。