iOS自定义UItableView标头

时间:2015-07-08 20:21:15

标签: ios objective-c uitableview

我是iOS开发的新手。我对Android和Android Studio非常熟悉,但我真的很挣iOS和xcode。

基本上我想要做的是在标题下添加另一个标题,通过创建UItableview提供给你。有没有办法通过故事板来做到这一点,或者代码是更好的选择?如果是这样,我该怎么做呢。我没有真正通过谷歌搜索找到太多关于这一点,我发现的信息并不是非常适用。

这是我的第一个问题,所以我无法添加图片。这就是它的样子,我想添加第二个标题,它将在EVENT NAME下显示日期和位置:

活动名称

-------------

3 个答案:

答案 0 :(得分:2)

从故事板中你可以将UIView拖到你的UITableView中,超过表格中的任何单元格,这将成为你的HeaderView。从那里你可以将任何你想要的东西拖到视图中。 enter image description here

答案 1 :(得分:0)

您可以在xib中创建视图并实现tableview委托方法

{  
   "movies_search":{  
      "@xmlns":"http://www.ourmoviest.com/mv",
      "@xmlns:xsi":"http://www.w3.org/2001/XMLSchema-instance",
      "@xsi:schemaLocation":"http://www.ourmoviest.com/mv mv.xsd ",
      "error":{  
         "errorMessage":"We cannot proceed search",
         "statusCode":"00004"
      }
   }
}

此处您可能需要为标题提供高度以显示自定义视图。

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
  // return custom xib view 
}

答案 2 :(得分:0)

您可以通过故事板进行操作,然后对要添加到其中的任何UIButtons,UILabels等使用标记。

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section 
{ 
   UITableViewCell *cell= [tableView dequeueReusableCellWithIdentifier:@"HEADER_CELL"];

   // Stuff you want to do to your header
   // Tag can be anything except 0. You set this in the interface builder
   UILabel * myHeaderLabel = (UILabel *)[cell viewWithTag:1];
   UILabel * myHeaderSubLabel = (UILabel *)[cell viewWithTag:1];

   myHeaderLabel.text = [NSString stringWithFormat:@"Section: %d", section];
   myHeaderLabel.text = @"Subtext";

   return cell; 
}