Я получаю предупреждение "Достигну конец не-void функции", но мне больше нечего вернуть компилятору. Как мне обойти предупреждение ??
Я использую customCells для отображения таблицы с 3 разделами. Каждый CustomCell отличается, связан с табличным представлением другого viewcontroller в приложении, и получает свои данные из своей отдельной модели. Все отлично работает в Симуляторе и Устройствах, но я хотел бы избавиться от предупреждения, которое у меня есть. Это единственный, который у меня есть, и он ожидает от меня загрузки в App Store!
В - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
я использовал 3 отдельных оператора If () - (т.е. == 0, == 1, == 2), чтобы контролировать, какие customCells отображаются в каждом разделе в ячейках табличного представления. Каждая из пользовательских ячеек была создана в IB, извлекает данные из разных моделей и используется с другими табличными представлениями ViewController.
В конце функции у меня нет «ячейки» или чего-либо еще, чтобы вернуть, потому что я уже указал, какой CustomCell должен возвращаться в каждом из операторов If ().
Поскольку на каждую из CustomCell ссылаются через AppDelegate, я не могу установить пустую ячейку в начале функции и просто установить пустую ячейку равной требуемой CustomCell в каждом из операторов If (), так как вы может для текста, этикетки и т. д. ...
Мой вопрос не касается исправления кода в операторах If (), если только это не требуется. Мои вопросы находятся в разделе «Как убрать предупреждение о достижении конца недействительной функции - (cellForRowAtIndexPath :), когда я уже вернул значение для каждого возможного случая: if (section == 0); if (section == 1) и если (раздел == 2).
* Code-Reference: Фактические имена файлов для простоты выбиты (раздел 0 относится к M, раздел 1 относится к D, а раздел 2 относится к B).
Вот примерный макет кода:
//CELL FOR ROW AT INDEX PATH:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//Reference to the AppDelegate:
MyAppDelegate *appDelegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];
//Section 0:
if(indexPath.section == 0) {
static NSString *CustomMCellIdentifier = @"CustomMCellIdentifier";
MCustomCell *mCell = (MCustomCell *)[tableView dequeueReusableCellWithIdentifier:CustomMCellIdentifier];
if (mCell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"MCustomCell" owner:tableView options:nil];
for (id oneObject in nib)
if ([oneObject isKindOfClass:[MCustomCell class]])
mCell = (MCustomCell *)oneObject;
}
//Grab the Data for this item:
M *mM = [appDelegate.mms objectAtIndex:indexPath.row];
//Set the Cell
[mCell setM:mM];
mCell.selectionStyle =UITableViewCellSelectionStyleNone;
mCell.root = tableView;
return mCell;
}
//Section 1:
if(indexPath.section == 1) {
static NSString *CustomDCellIdentifier = @"CustomDCellIdentifier";
DCustomCell *dCell = (DCustomCell *)[tableView dequeueReusableCellWithIdentifier:CustomDaddyCellIdentifier];
if (dCell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"DCustomCell" owner:tableView options:nil];
for (id oneObject in nib)
if ([oneObject isKindOfClass:[DCustomCell class]])
dCell = (DCustomCell *)oneObject;
}
//Grab the Data for this item:
D *dD = [appDelegate.dds objectAtIndex:indexPath.row];
//Set the Cell
[dCell setD:dD];
//Turns the Cell's SelectionStyle Blue Highlighting off, but still permits the code to run!
dCell.selectionStyle =UITableViewCellSelectionStyleNone;
dCell.root = tableView;
return dCell;
}
//Section 2:
if(indexPath.section == 2) {
static NSString *CustomBCellIdentifier = @"CustomBCellIdentifier";
BCustomCell *bCell = (BCustomCell *)[tableView dequeueReusableCellWithIdentifier:CustomBCellIdentifier];
if (bCell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"BCustomCell" owner:tableView options:nil];
for (id oneObject in nib)
if ([oneObject isKindOfClass:[BCustomCell class]])
bCell = (BCustomCell *)oneObject;
}
//Grab the Data for this item:
B *bB = [appDelegate.bbs objectAtIndex:indexPath.row];
//Set the Cell
[bCell setB:bB];
bCell.selectionStyle =UITableViewCellSelectionStyleNone;
bCell.root = tableView;
return bCell;
}
//** Getting Warning "Control reaches end of non-void function"
//Not sure what else to "return ???" all CustomCells were specified within the If() statements above for their corresponding IndexPath.Sections.
}
Любые предложения ??