我试图在 TableView 的副标题中记录日期和时间我使用了一个数组作为副标题,就像我对文本字段所做的那样,但它不适用于副标题。难道我做错了什么?我为带有 * 的字幕添加的代码。
-(IBAction)save{
*NSDate *now = [NSDate date];
*NSLog(@"now: %@", now); // now: 2012-02-28 09:57:49 +0000
*NSString *strDate = [[NSString alloc] initWithFormat:@"%@",now];
NSUserDefaults *add1 = [NSUserDefaults standardUserDefaults];
NSMutableArray *myList = [[[NSUserDefaults standardUserDefaults] valueForKey:@"myTxtList"] mutableCopy];
*NSMutableArray *myDate = [[[NSUserDefaults standardUserDefaults] valueForKey:@"myDateList"] mutableCopy];
[myList addObject:txt1.text];
*[myDate addObject:strDate];
[[NSUserDefaults standardUserDefaults] setObject:[NSArray arrayWithArray:myList] forKey:@"myTxtList"];
*[[NSUserDefaults standardUserDefaults] setObject:[NSArray arrayWithArray:myDate] forKey:@"myDateList"];
[add1 synchronize];
self.dataArray = myList;
*self.dateArray = myDate;
[self.tbl1 reloadData];
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.dataArray = [[NSUserDefaults standardUserDefaults] objectForKey:@"myTxtList"];
*self.dateArray = [[NSUserDefaults standardUserDefaults] objectForKey:@"myDateList"];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [dataArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *string = [dataArray objectAtIndex:indexPath.row];
*NSString *dateString = [dateArray objectAtIndex:indexPath.row];
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell==nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLabel.text = string;
*cell.detailTextLabel.text = dateString;
return cell;
}