[英]iOS UITableView numberOfRowsInSection in tableView heightForRowAtIndexPath give BAD ACCESS
I have receive a EXC Bad Access error when I enter the if statement below [tableView numberOfRowsInSection:0]
.I'm calculating the tableView numberOfRowsInSection
of the UITableView inside the heightForRowAtIndexPath . 我在[tableView numberOfRowsInSection:0]
下输入if语句时收到EXC错误访问错误。我正在计算heightForRowAtIndexPath内部的UITableView的tableView numberOfRowsInSection
。
I have got following code to set height for last row of first section 我有以下代码来设置第一部分最后一行的高度
-(CGFloat )tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.section==0) {
NSInteger lastRowIndex = [tableView numberOfRowsInSection:0] - 1;
if (indexPath.row==lastRowIndex) {
return 44.0f;
}else{
return 100;
}
}else{
return 100;
}
}
I got the error as below image 我收到如下图所示的错误
I didnt find this method appropriate 我没有发现这种方法合适
iOS UITableView numberOfRowsInSection BAD ACCESS iOS UITableView numberOfRowsInSection错误访问
- (int) myNumberOfRowsMethod{
// Here you would usually have some underlying model
return [self.myContactsOrWhateverArray count];
}
Try this method [self tableView:tableView numberOfRowsInSection:0]
instead of [tableView numberOfRowsInSection:0]
. 尝试使用此方法[self tableView:tableView numberOfRowsInSection:0]
而不是[tableView numberOfRowsInSection:0]
。 It's works fine. 很好
Update your code to following 更新您的代码以关注
-(CGFloat )tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.section==0) {
NSInteger lastRowIndex = [self numberOfRowsInSection:indexPath.section] - 1;
if (indexPath.row==lastRowIndex) {
return 44.0f;
}else{
return 100;
}
}else{
return 100;
}
}
Please Try With This. 请尝试与此。 Make one Global NSinteger firstSectionCount; 首先使一个全局NSintegerSectionCount; and then try with this. 然后尝试这个。
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
if (section==0){
firstSectionCount = [ storeArr count];
return [ storeArr count]+1;
}else{
return [ [[itemArr objectAtIndex:section-1] objectForKey:@"itemList"]count];
}
and then,,,, 接着,,,,
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section==0) {
if (indexPath.row==firstSectionCount) {
return 44.0f;
}else{
return 100;
}
}
else{
return 100;
}
Hope this will help you... 希望这个能对您有所帮助...
Try this code: 试试这个代码:
-(CGFloat )tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.section==0) {
long lastRowIndex = [self.yourArray count]-1;
// other wise use this line
// long lastRowIndex = [self.yourArray lastObject]-1;
if (indexPath.row==lastRowIndex) {
return 44.0f;
}else{
return 100;
}
}else{
return 100;
}
}
Because this numberOfRowsInSection
not work heightForRowAtIndexPath
delegate method. 因为此numberOfRowsInSection
不起作用heightForRowAtIndexPath
委托方法。
Try this.. 尝试这个..
-(CGFloat )tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.section==0) {
NSInteger lastRowIndex = yourArray.count - 1;
if (indexPath.row==lastRowIndex) {
return 44.0f;
}else{
return 100;
}
}else{
return 100;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.