我是新来的Objective C,我试图在我的tableView中指定numberOfSectionsInTableView
这里是我的代码。填充numberOfSectionsInTableView使用NSMutableArray
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [_dateSectionTitles count];
}
[_dateSectionTitles count]
总是返回零。
这是我如何得到_dateSectionTitles
- (void) dictionaryItems {
NSMutableDictionary* dates = [NSMutableDictionary dictionary];
_dateSectionTitles = [[NSMutableArray alloc] init];
for (myObject *cItem in _cashArray) {
NSString* dateString = [cItem.date stringFormattedWithDayAndFullMonth];
array = [dates valueForKey: dateString];
if(!array)
{
array = [@[cItem] mutableCopy];
[dates setObject:array forKey: dateString];
[_dateSectionTitles addObject:dateString];
}
else
{
[array addObject: cItem];
}
}
}
它在我的'@接口视图控制器(){ 的NSMutableArray *数组声明; }' – 2015-03-02 18:57:33
那还不够。根据你的**其他**你必须初始化它或不会添加任何对象。这可能是正在发生的事情。声明它是不够的,你需要初始化它使用** [array addobject:cItem] ** – Chase 2015-03-02 19:00:28
也在你的if - else .... if数组= [日期valueForString:dateString]总是返回一个数组永远不会被添加到_dateSectionTitles,因为只有你的else语句会被执行。 – Chase 2015-03-02 19:05:58