任何幫助將不勝感激,我一直堅持了這一段時間。我添加了內容到我的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
做一些調試。將日誌放在表數據源方法中。這些方法被稱爲?此外,它似乎永遠不會向arrParkingList添加任何內容,那麼您爲什麼期望看到任何東西? – rdelmar