小编wal*_*ace的帖子

在UITableView中只调用一次viewForHeaderInSection

虽然我确信这是一件非常简单的事情,但我已经筋疲力尽了谷歌.

我正在尝试创建一个UITableView,表示25个(比方说)对象,每个对应25个部分,每行1行.

我正在创建的自定义单元格显示正常(所有25个,按正确顺序).我想在每个对象上方显示一个节头视图.

问题是只显示了一个节标题视图(第一个).

明智的NSLogging告诉我,只有一次调用viewForHeaderInSection,尽管每个对象调用heightForHeaderInSection 2x.我从numberOfSectionsInTableView返回25,从numberOfRowsInSection返回1.

我在viewForHeaderInSection中构建一个UIView,UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, viewHeight)]然后添加一个UILabel和一个UIButton.我不是UITableViewHeaderFooterView的子类.不确定这是否有所不同.

有任何想法吗?

相关代码:

部分和行数:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return [self.objects count];
}

- (NSInteger)numberOfRowsInSection:(NSInteger)section
{
    return 1;
}
Run Code Online (Sandbox Code Playgroud)

行的高度和单元格:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 390;
}

- (UITableViewCell *)tableView:(UITableView *)tableView
         cellForRowAtIndexPath:(NSIndexPath *)indexPath
                        object:(PFObject *)object
{
    static NSString *CellIdentifier = @"CustomCell";    
    CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    // add custom content to cell

    return cell;
}
Run Code Online (Sandbox Code Playgroud)

标题的高度和视图:

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return …
Run Code Online (Sandbox Code Playgroud)

iphone objective-c uitableview ios

5
推荐指数
2
解决办法
1516
查看次数

如何懒惰地在Objective-C中设置BOOL属性

我需要一个数据结构上的BOOL属性,表示数据库中某个对象的状态,我想懒惰地设置该属性 - 也就是说,我不想在需要之前ping数据库,并且只设置那个时候的财产(也就是我第一次得到它).

对于像NSString这样的东西,我会像吸气鬼一样

- (NSString *)myString {
    if (!_myString) {

        // ask db for value
        _myString = [value returned from db]

    }
    return _myString;
}
Run Code Online (Sandbox Code Playgroud)

但似乎BOOL在Objective-C中默认为NO - 这意味着我永远不会知道该值是否实际上是NO,或者我还没有得到它.我已经开玩笑了,但我似乎无法弄清楚如何为这样的属性创造我想到的那种吸气剂.有什么建议?或者我错过了一些非常明显的东西?提前致谢.

boolean objective-c getter-setter ios

3
推荐指数
1
解决办法
625
查看次数

保存Parse PFInstallation对象时丢失的字段

我在应用程序中保存了一个PFInstallation对象:didFinishLaunchingWithOptions - 我没有要求用户提供推送权限或与deviceToken有关 - 我发现很多标准字段都没有填充,包括:

  • appIdentifier
  • appVersion
  • APPNAME
  • 徽章
  • parseVersion
  • 时区

(这些列在数据浏览器中未定义,并且不显示在PFInstallation对象的NSLog上.)

  • deviceType 确实已填充

我抓住并成功将deviceModel和deviceOS保存到两个自定义列.但我有点困惑的是为什么上面的列未被定义.

这是代码:

[Parse setApplicationId:PARSE_APPID_DEV
              clientKey:PARSE_CLIENTKEY_DEV];

// record device model and OS
NSString *model = [self getDeviceModelAndNumber]; // via sys/utsname.h
NSString *sysVersion = [[UIDevice currentDevice] systemVersion];

PFInstallation *currentInstallation = [PFInstallation currentInstallation];
PFUser *loggedUser = [PFUser currentUser];
if (loggedUser)
    [currentInstallation setObject:loggedUser forKey:@"user"];

[currentInstallation setObject:model forKey:@"deviceModel"];
[currentInstallation setObject:sysVersion forKey:@"deviceOS"];
NSLog(@"installation: %@", currentInstallation);
[currentInstallation saveInBackground];
Run Code Online (Sandbox Code Playgroud)

这个项目是在Xcode 6中创建的.在Xcode 5中创建的一个不同的项目中,我基本上做了同样的事情,并且正在填充和保存列.

其他人遇到这个吗?我已经谷歌搜索了相当多但没有找到解决方案.任何帮助非常感谢.

xcode ios parse-platform

2
推荐指数
1
解决办法
2244
查看次数