0

我正在为课堂制作一些信息指南。我需要使用UITableView,少这个东西看起来像废话,所以我已经研究了大约一个星期。

我收到的错误是以下代码中的 NSInvalidArgumentException:

- (NSInteger)numberOfRowsInSection:(NSInteger)section{
/*NSDictionary *dict = [_allPerks objectAtIndex:section];
NSArray *temp = [dict objectForKey:@"Perks"];
return [temp count];*/
if (section == 0)
    return 9;
else if (section ==1)
    return 7;
else if (section ==2)
    return 11;
else if (section == 3)
    return 11;
else if (section == 4)
    return 8;
else
    return 0;

}

至少,我认为它就在那里。该错误表明我的问题出在该函数中,它的发件人无效。注释的代码是我的第二次尝试,但没有成功。

这也是一个分组表,以防万一。我正在使用一组数组来实现这一点,因为我需要组织很多元素。如果代码是必要的,就这么说吧。

4

2 回答 2

0

确保您的方法签名与此匹配:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

而不是这个:

- (NSInteger)numberOfRowsInSection:(NSInteger)section
于 2013-03-13T20:16:52.557 回答
0

试试这个代码

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    if (section == 0){
          return 9;
    }
    else if (section ==1){
          return 7;
    } 
    else if (section ==2){
          return 11;
    }
    else if (section == 3){
          return 11;
    }
    else if (section == 4){
          return 8;
    }
    else{
          return 0;
    }
}
于 2013-03-14T04:56:20.540 回答