如何将UITableView节索引用作NSInteger?

时间:2015-06-23 03:51:58

标签: ios objective-c uitableview

我想将JTCalendarkJTCalendarDaySelected设置为等于可见的index.section。如果索引为0,我希望kJTCalendarDaySelected设置为1(本月的第1个),如果索引为1,我希望将其设置为2(本月的第2个),依此类推。

当我尝试这样做时:

-(BOOL)whatSectionsAreVisible {
    NSArray *visibleRowIndexes = [self.agendaTable indexPathsForVisibleRows];
    for (NSIndexPath *index in visibleRowIndexes) {

        self.daySection = index.section;

        // Update views
        [[NSNotificationCenter defaultCenter] postNotificationName:@"kJTCalendarDaySelected" object:self.daySection];

        // Store currentDateSelected
        [self.calendar setCurrentDateSelected:self.daySection];

        NSLog(@"The visible section has an index of: %ld", (long)index.section);

        if (index.section == 0) {
            NSLog(@"index.row is indeed 0");
            return YES;
        }
    }
    return NO;
}

我收到以下错误:

implicit conversion of non-Objective-c pointer type 'NSInteger' (aka 'long') to 'id' is disallowed with ARC enter image description here

如何将index.section的id转换为可用于此目的的NSInteger?

2 个答案:

答案 0 :(得分:0)

您需要传递参数类型ID。 假设你可以这样使用..

NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInteger:self.daySection],@"sectionIndex", nil];
[[NSNotificationCenter defaultCenter] postNotificationName:@"kJTCalendarDaySelected" object:dict];

希望这会对你有帮助......

答案 1 :(得分:0)

您可以使用以下代码删除错误

[[NSNotificationCenter defaultCenter] postNotificationName:@"kJTCalendarDaySelected" object:[NSNumber numberWithInteger:self.daySection]];

NSString *strDate = [NSString stringWithFormat:@"%@", [NSNumber numberWithInteger:section]];

NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
[formatter setDateFormat:@"MM"];
[formatter setDateStyle:NSDateFormatterMediumStyle];

NSDate *selecteDate = [[formatter standaloneMonthSymbols] objectAtIndex:[formatter dateFromString:strDate]];

NSLog(@"%@",selectedDate);

如果你的indexpath.section是" 0"那么selectedDate将以月名的形式出现。然后它会给你一月'所以你可以在日历中设置月份名称。