2015-07-28 25 views
0

У меня есть сообщение об ошибке EXC Bad Access, когда я вхожу, если заявление ниже [tableView numberOfRowsInSection:0] .Я Вычисляя tableView numberOfRowsInSection в UITableView внутри heightForRowAtIndexPath.IOS UITableView numberOfRowsInSection в Tableview heightForRowAtIndexPath дают BAD ДОСТУПА

Я получил следующий код, чтобы установить высоту для последней строки первой секции

-(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; 
     } 


} 

я получил ошибку ниже изображения

enter image description here

Я не нахожу это метод соответствует

iOS UITableView numberOfRowsInSection BAD ACCESS

- (int) myNumberOfRowsMethod{ 
    // Here you would usually have some underlying model 
    return [self.myContactsOrWhateverArray count]; 
} 
+0

Невозможно использовать какую-то вещь, как tableView numberOfRowsInSection, этот метод работает лучше, чем подсчет массива –

+0

, что у вас есть в методе 'numberOfRowsInSection'? Я думаю, вместо '[tableView numberOfRowsInSection: 0] - 1;' вы можете использовать '[self myNumberOfRowsMethod] - 1;' – Akhilrajtr

+0

Я не хотел использовать myNumberOfRowsMethod, я хочу использовать несколько лучших методов, поэтому bro –

ответ

1

Обновить код к следующему

-(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; 
     } 
} 
+0

Я проверю, что –

+0

какая разница в вашем ответе по сравнению с вопросом, уже условие проверено isEqual на 0 \ –

+0

, что не работает чувак –

0

Попробуйте этот код:

-(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; 
     } 
} 

Поскольку это numberOfRowsInSection не работает heightForRowAtIndexPath метод делегата.

+0

используйте этот код, который вы не получите. @nischal hada –

+0

Я попробую это бросить и ответит u –

+0

нормально, но я пробую ваш код, я не получаю ошибку. @nischalhada –

1

Пожалуйста, попробуйте с этим. Сделайте один глобальный NSinteger firstSectionCount; , а затем попробуйте с этим.

- (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]; 
} 

, а затем ,,,,

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { 
if (indexPath.section==0) { 
    if (indexPath.row==firstSectionCount) { 
     return 44.0f; 

    }else{ 
     return 100; 

    } 
} 
else{ 
     return 100; 
} 

Надеется, что это поможет ...

+0

можно проверить этот вопрос http://stackoverflow.com/questions/31692692/what-could-we-do-in-case-of-custom-cell- in-viewforheaderinsection-to-reload-part –

+0

У меня есть upvote для усилий –

0

Попробуйте это ..

-(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; 
    } 
} 
+0

можно проверить этот вопрос http://stackoverflow.com/questions/31692692/what-could-we-do-in-case-of-custom- cell-in-viewforheaderinsection-to-reload-part –

+0

У меня есть upvote для усилий –

2

Попробуйте этот метод [self tableView:tableView numberOfRowsInSection:0] вместо [tableView numberOfRowsInSection:0]. Это прекрасно работает.

+0

можно проверить этот вопрос http://stackoverflow.com/questions/31692692/what-could-we-do-in-case-of- custom-cell-in-viewforheaderinsection-to-reload-part –

+0

У меня есть выдвижение для усилий –

+0

Благодарим вас за upvote @nischal hada. – Vishnuvardhan

Смежные вопросы