【问题标题】:Adding a Header to and NSArray for a Dynamic Table cell为动态表格单元格添加标题和 NSArray
【发布时间】:2012-08-21 16:59:11
【问题描述】:
[super viewDidLoad];

self.Lodgelist = [[NSArray alloc]
                  initWithObjects:@"Sterling ",
                  @"Sterling location  1234",
                  @"Sterling  location 12345",nil];

这是我的代码示例。我希望标题是城市名称“Sterling”我是 Objective-c 的新手。再次感谢您的帮助。

P.S 我不确定如何或将要添加代码。

【问题讨论】:

  • 简而言之,你想将 Header 添加到 UITableview 中吗?
  • 我不明白。你想要一个列标题为“Sterling”的 1x3(一列)表吗?
  • 我想为上面的列表设置一个标题。 NSArray 位于动态分组表格单元格中。我希望每个组都有不同的标题。

标签: iphone ios xcode cocoa ios4


【解决方案1】:

在 ViewController 的 header 中添加 UITableViewDelegate,然后添加以下代码来更改 UITableView 的 header

 - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section

    {
         return [self.Lodgelist objectAtIndex:0];
    }

【讨论】:

  • 当你说标题是在#import 或@implementation 下? .m 视图控制器的
  • @interface URViewController : UIViewController 在 vi​​ewController .h 文件中
  • 我在第一个 { 处收到“预期标识符或')'”错误
  • 我对所有这些编码都是新手.. 它应该是什么样子?
  • 你能对数组做同样的事情吗?
【解决方案2】:

如果您只想将标题设置为标题,请使用

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
     return [self.Lodgelist objectAtIndex:section];
}

如果你想在部分标题(或某些视图)中添加一些图像和其他内容,请使用

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section

【讨论】:

  • 我试图为我拥有的每个不同的 NSArray 放置一个标题。我在每个城市都有几个位置。我希望对每个城市进行分组并列出位置
  • 该代码应该放在哪里?这就是我现在所拥有的。对于我的位置列表。我想给它一个标题。 self.Lodgelist = [[NSArray alloc] initWithObjects:@"Sterling Lodge 123", @"Sterling Lodge 1234", @"Serling Lodge 12345",nil];
  • 我不明白你现在在说什么?
猜你喜欢
  • 2014-05-25
  • 2016-05-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-08-13
相关资源
最近更新 更多