所以我在重新加载数组后尝试重新加载表格。
我可以告诉数据在数组中,但它没有显示在表中
然而,当我将数组设置为nil时,表会更新,所以我知道它与更新数组的方式有关
编辑:我一直在尝试调试,我可以看到数组中的对象,但他们不想重新加载......EDIT2:所以UITableView在调试框中打印为Nil
标题:
@interface SecondViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>
{
NSMutableArray *historyData;
NSArray *coords0;
NSArray *coords1;
NSArray *coords2;
NSArray *coords3;
NSArray *coords4;
NSArray *coords5;
NSArray *coords6;
NSArray *coords7;
NSArray *coords8;
NSArray *coords9;
IBOutlet UITableView *tableview;
NSString *LocatedAt;
}
-(void)setTableValue;
-(NSString *)getAddressForCoords: (NSArray * )coord : (int) number;
- (IBAction)clearAction:(id)sender;
@property(nonatomic,retain) CLLocationManager *locationManager;
@property (nonatomic, retain) IBOutlet UITableView *tableView;
@property (nonatomic, retain, readwrite) NSMutableArray *historyData;
@end
方法:
-(void)setTableValue {
historyData = [[NSMutableArray alloc] init];
if (coords0 != nil)
[historyData addObject:[self getAddressForCoords:coords0]];
if (coords1 != nil)
[historyData addObject:[self getAddressForCoords:coords1]];
if (coords2 != nil)
[historyData addObject:[self getAddressForCoords:coords2]];
if (coords3 != nil)
[historyData addObject:[self getAddressForCoords:coords3]];
if (coords4 != nil)
[historyData addObject:[self getAddressForCoords:coords4]];
if (coords5 != nil)
[historyData addObject:[self getAddressForCoords:coords5]];
if (coords6 != nil)
[historyData addObject:[self getAddressForCoords:coords6]];
if (coords7 != nil)
[historyData addObject:[self getAddressForCoords:coords7]];
if (coords8 != nil)
[historyData addObject:[self getAddressForCoords:coords8]];
if (coords9 != nil)
[historyData addObject:[self getAddressForCoords:coords9]];
NSLog(@"%@",historyData[0]);
[self.tableView reloadData];
}
-(NSString *)getAddressForCoords: (NSArray * )coord { //Not done yet
float lat = [coord[0] floatValue];
float lon = [coord[1] floatValue];
LocatedAt = [NSString stringWithFormat:@"Lat: %f Long: %f", lat, lon];
return LocatedAt;
}
这就是工作......
-(IBAction)clearAction:(id)sender
{
[historyData removeAllObjects];
NSLog(@"Cleared all memory slots");
[self.tableView reloadData];
}
表格方法
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [historyData count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = nil;
cell = [tableview dequeueReusableCellWithIdentifier:@"Cell"];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
}
// if ([historyData count] > 0)
cell.textLabel.text = [historyData objectAtIndex:indexPath.row];
return cell;
}