我新建了一个tableview想向其中增加54个cell,内容分别是:第1周、第2周、。第54周不知道该怎么写(我是新手,麻烦大侠写的详细一点)
非常非常感谢!!!!!!!!

解决方案 »

  1.   

    @interface XXXX : XXXX<UITableViewDataSource, UITableViewDelegate>@implementation XXXX
    初始化方法里:
        tableview.dataSource = self;
        tableview.delegate = self;下边是需要实现的UITableViewDataSource, UITableViewDelegate里的函数
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
        return 行数;
    }- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        NSString *cellId = @"XXXX";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId]; 
        if(cell == nil)
        {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
        }
        
        cell.backgroundColor = [UIColor XXXXX];
        cell.textLabel.text = @"";
        cell.textLabel.font = [UIFont systemFontOfSize:XXXX];
        
        cell.selectionStyle = UITableViewCellSelectionStyleBlue;
        cell.textLabel.textAlignment = self.listTextAlignment;
        
        return cell;
    }- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        return 行高;
    }
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
        行点击事件
    }
      

  2.   

    把 第1周、第2周、。第54周存储到一个NSMutableArray 中
    NSMutableArray *array=[NSMutableArray arrayWithObjects:@"第1周",@"第2周",....,nil];在- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section中
    return [array count];在- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 中取值
    NSString *title=[array objectAtIndex:indexPath.row];