UItableView不显示我的内容

时间:2013-08-24 19:06:31

标签: ios objective-c uitableview

任何帮助都将受到赞赏,我已经坚持了很长一段时间。我将内容添加到我的UITableView并重新加载数据没有任何反应,我无法弄清楚我的停车列表控制器发生了什么。那么这是我正在使用的代码。

.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

3 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:1)

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

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

同样@synthesize tblParkingList;

之后你已经初始化了一个数组arrParkingList来填充表。添加内容,因为它是空的。

答案 2 :(得分:0)

您应该确保将类设置为tableview的委托和tableview的数据源委托。您可以在故事板中通过控制从tableView拖动到栏左侧的图标,或者将以下代码行添加到您的应用程序中来完成此操作。

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

还要确保将tableView声明为.h文件中的插座。我假设您在上面的示例中将其拖动为名为“tableView”的插座。

希望有所帮助!