Obj-C-在UITableView中显示一系列日期吗?

问题描述

我正在使用以下代码检索一系列7个日期,并将它们添加到NSMutableArray中。

也就是说,我想在每个单元格的UILabel中显示存储在数组中的每个日期(请参见下文)。我该如何写UILabel行,以便将日期拉出工作日?

Dashboard.h

@property (weak,nonatomic) IBOutlet UITableView *todaytableView;
@property (strong,nonatomic) NSMutableArray *weekdates;

DashboardViewController.m

 - (void)viewDidLoad {
    [super viewDidLoad];

      _weekdates = [[NSMutableArray alloc] init]; //Add this line

       NSDate *today = [NSDate date];
       NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
       NSCalendar *calendar = [NSCalendar currentCalendar];
       dateFormatter.dateFormat = @"ddMMM";
       for (UInt16 i = 0; i < 7; i++) {
           NSDate *nextDate = [calendar dateByAddingUnit:NSCalendarUnitDay value:i toDate:today options: 0];
           [_weekdates addObject:nextDate];
           NSLog(@"Weekdate %d = %@",i+1,[dateFormatter stringFromDate: nextDate]);
           
       }

}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  
    return 6;
    
}


-(UITableViewCell *)tableView:(UITableView*)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
    
    
    if (tableView == self.todaytableView) {
        
              
    
    static NSString *WeeklyTableIdentifier = @"TimeTableViewCell";
    
    TimeTableViewCell *cell = (TimeTableViewCell *)[self.todaytableView dequeueReusableCellWithIdentifier:WeeklyTableIdentifier];
    
    if (cell == nil)
    {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"TimeTableViewCell" owner:self options:nil];
        cell = [nib objectAtIndex:0];
        
    }
    
     
        cell.firstLast.text = [NSString stringWithFormat:@"%@",_weekdates[indexPath.row]];
       
        
        
    return cell;
    
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)