배열을 초기화하기 전에 테이블보기를 다시로드하거나 배열을 사용할 때 배열이 비어있을 수 있습니다! 사용할 때처럼
: cellForRowAtIndexPath에서
NSString *xyz = [self.your_array objectAtIndex:indexPath.row];
는, 늘 당신의 응용 프로그램을 충돌 코드를 fllowing보십시오!
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"xyz_cell";
long nodeCount = [self.your_array count];
if (nodeCount == 0 && indexPath.row == 0)
{
Home_CellTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[Home_CellTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:CellIdentifier] ;
cell.lbl.textAlignment = NSTextAlignmentCenter;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
cell.lbl.text = @"No Posts yet !";
return cell;
}
else{
Home_CellTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if (cell == nil) {
cell = [[Home_CellTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
} // Your Code Goes HERE .... NSString *xyz = [self.your_array objectAtIndex:indexPath.row]; }
그래서 빈 배열의 경우 키 하나의 값을 찾지 못하고 앱이 다운되지 않습니다!
도움이 되었기를 바랍니다.