2013-08-24 65 views
0

任何幫助將不勝感激,我一直堅持了這一段時間。我添加了內容到我的UITableView並重新加載數據沒有任何反應,我無法完全弄清楚我的parkinglistviewcontroller發生了什麼。那麼這是我正在使用的代碼。UItabelView不顯示我的內容

.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 
+0

做一些調試。將日誌放在表數據源方法中。這些方法被稱爲?此外,它似乎永遠不會向arrParkingList添加任何內容,那麼您爲什麼期望看到任何東西? – rdelmar

回答

1

在viewDidLoad方法添加以下:

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

另外@synthesize tblParkingList;

之後,您已經初始化了一個數組arrParkingList來填充表格。添加內容給它,因爲它是空的。

+0

是什麼意思? – mrorgon

+0

在viewDidLoad的最後寫這個。 – Apoorv

+0

看起來像你的數據源和委託未設置。 – Apoorv

0

你應該確保你設置類爲代表的tableview和tableview的數據源委託。您可以通過控制從的tableView拖動到圖標上欄的左側,或通過添加下面的代碼行到你的應用程序在情節串連圖板做..

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

另外,還要確保你的tableView在.h文件中聲明爲出口。我假設你在上面的例子中把它作爲一個叫做「tableView」的插座來拖動它。

希望有幫助!

+0

我應該在哪裏添加這個? – mrorgon

+0

將它放在「viewDidLoad」 – AdamG

1

除了AdamG的評論,我看到你已經爲arrParkingList數組分配了空間,但是我看不到你給它添加值或初始化它的位置。