2013-08-24 3 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

다음 추가 또한

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

@synthesize tblParkingList;

그 다음에는 테이블을 채우는 arrParkingList 배열을 초기화했습니다. 비어있어 table.Add 내용을 채 웁니다.

+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 배열에 대한 공간이 할당 된 것을 볼 수 있지만 값을 추가/초기화 할 수는 없습니다. 방법에서의 viewDidLoad

관련 문제