0

任何帮助将不胜感激,我已经坚持了很长一段时间。我将内容添加到我的 UITableView 并重新加载数据没有任何反应,我无法弄清楚我的 parklistviewcontroller 发生了什么。好吧,这是我正在使用的代码。

.m 文件

@implementation ParkingListViewController
@synthesize objCustomCell;

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

- (void)viewDidLoad
{
    [super viewDidLoad];
    arrParkingList = [[NSMutableArray alloc] init];
    appDelegate = [[UIApplication sharedApplication] delegate];
    locationManager = [[CLLocationManager alloc] init];
    arrAnnotations = [[NSMutableArray alloc] init];
    // Do any additional setup after loading the view from its nib.
}

-(void)viewWillAppear:(BOOL)animated
{
    [self locate];
    [parkingMap setRegion:MKCoordinateRegionMakeWithDistance(parkingMap.userLocation.coordinate, 5, 5) animated:YES];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)dealloc
{
    [locationManager release];
    [tblParkingList release];
    [parkingMap release];
    [super dealloc];
}

- (void)viewDidUnload
{
    [tblParkingList release];
    tblParkingList = nil;
    [parkingMap release];
    parkingMap = nil;
    [super viewDidUnload];
}


#pragma mark - Tableview Methods

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return arrParkingList.count;
}

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    ParkingCustomCell *cell = (ParkingCustomCell*)[tableView dequeueReusableCellWithIdentifier:@"CellIdentifier"];

    if (cell == nil)
    {
        [[NSBundle mainBundle] loadNibNamed:@"ParkingCustomCell" owner:self options:nil];
        cell = self.objCustomCell;
        self.objCustomCell = nil;
    }

    ClsParking *objTmpParking = [arrParkingList objectAtIndex:indexPath.row];
    cell.lblTitle.text = objTmpParking.strLocation;
    cell.imgUserImage.layer.masksToBounds = YES;
    cell.imgUserImage.layer.cornerRadius = 20;
    [cell.imgUserImage setImageWithURL:[NSURL URLWithString:objTmpParking.strImageUrl] placeholderImage:nil];
    return  cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 68;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

    ClsParking *objParking = [arrParkingList objectAtIndex:indexPath.row];

    float fltLatitude = [objParking.strLatitude floatValue];
    float fltLongitude = [objParking.strLongitude floatValue];

    CLLocationCoordinate2D pLocation = CLLocationCoordinate2DMake(fltLatitude, fltLongitude);

    [self setMapCenter:pLocation];

}

- (IBAction)btnAddTapped:(id)sender
{
    ParkingNotificationViewController *objParkingNotificationViewController =[[ParkingNotificationViewController alloc] initWithNibName:@"ParkingNotificationViewController" bundle:nil];
    [self presentViewController:objParkingNotificationViewController animated:YES completion:nil];
    [objParkingNotificationViewController release];
}

- (IBAction)btnBackTapped:(id)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}



@end

.h 文件

@class ParkingCustomCell;
@interface ParkingListViewController : UIViewController <UITableViewDataSource,UITableViewDelegate,CLLocationManagerDelegate,MKMapViewDelegate>
{
    IBOutlet UITableView *tblParkingList;
    NSMutableArray *arrParkingList;
    AppDelegate *appDelegate;
    CLLocationManager *locationManager;
    IBOutlet MKMapView *parkingMap;
    NSMutableArray *arrAnnotations;
}
@property (nonatomic,retain) IBOutlet ParkingCustomCell *objCustomCell;

- (IBAction)btnAddTapped:(id)sender;
- (IBAction)btnBackTapped:(id)sender;

@end

这是我的parkingcustomcell类

@implementation ParkingCustomCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)dealloc {
    [_lblTitle release];
    [_imgUserImage release];
    [super dealloc];
}
@end
4

3 回答 3

1

在 viewdidload 方法中添加以下内容:

self. tblParkingList.delegate = self;
self. tblParkingList.delegate = self;

还有@synthesize tblParkingList;

之后,您已经初始化了一个数组 arrParkingList 以填充表格。向其中添加内容,因为它是空的。

于 2013-08-24T19:56:06.640 回答
1

除了 AdamG 的评论,我看到你已经为arrParkingList数组分配了空间,但我看不到你在哪里添加值/初始化它。

于 2013-08-24T19:39:18.090 回答
0

您应该确保将类设置为 tableview 的委托和 tableview 的数据源委托。您可以在情节提要中执行此操作,方法是控制从 tableView 拖动到栏左侧的图标,或者将以下代码行添加到您的应用程序中。

 self.tableView.delegate = self;
 self.tableView.dataSource = self;

还要确保你的 tableView 在你的 .h 文件中被声明为一个出口。我假设您在上面的示例中将它作为一个名为“tableView”的插座拖动。

希望有帮助!

于 2013-08-24T19:36:13.650 回答