任何帮助将不胜感激,我已经坚持了很长一段时间。我将内容添加到我的 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