我是新來的ios開發,但我做的是這樣的:我有一個表格視圖,我實現了顯示日期選擇器,當第一個單元格點擊表格視圖[日期選擇器將顯示在第一個單元格下方]。所以現在我想根據日期選擇器中選擇的日期重新加載單元格,但是整個表格視圖不應該重新加載,因爲允許顯示日期選擇器的第一個單元格應該始終存在。如何加載單元格而不影響iOS中表格視圖的第一個單元格
所以我想加載一些數據的單元格而不影響第一個單元格。我怎樣才能做到這一點。我有這樣一個想法:
如果我可以識別除第一個單元格之外的剩餘單元格,那麼我可以在我的cellForRowAtIndexpath
方法中使用if條件,但我不知道如何識別剩餘的單元格..請別人幫助我。我將把我的代碼如下..
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell;
NSDate *today = [NSDate date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
// display in 12HR/24HR (i.e. 11:25PM or 23:25) format according to User Settings
[dateFormatter setTimeStyle:NSDateFormatterShortStyle];
NSString *currentTime = [dateFormatter stringFromDate:today];
NSDate *date=[dateFormatter dateFromString:currentTime];
if(indexPath.row==0){
VCPerson *person = self.persons[indexPath.row];
cell = [self createPersonCell:person];
}
else if ([self datePickerIsShown] && (self.datePickerIndexPath.row == indexPath.row)){
// VCPerson *person = self.persons[indexPath.row -1];
cell = [self createPickerCell:date];
}
if(indexPath.section!=0 && tapfirstCell) {
UITableViewCell *cell = (UITableViewCell*)[self.tableView dequeueReusableCellWithIdentifier:kOtherCellIdentifier forIndexPath:indexPath];
//cell.delegate_Dtepick = self;
NSDictionary *dictionary = [_dataArray objectAtIndex:indexPath.section];
NSArray *array = [dictionary objectForKey:@"data"];
NSString *cellValue = [array objectAtIndex:indexPath.row];
cell.textLabel.text =cellValue;
}
return cell;
/*
if ([self datePickerIsShown] && (self.datePickerIndexPath.row == indexPath.row)){
// VCPerson *person = self.persons[indexPath.row -1];
cell = [self createPickerCell:date];
}
else {
// cellForDatePickCell* cell;
VCPerson *person = self.persons[indexPath.row];
cell = [self createPersonCell:person];
//cell = [self createCustomCell:indexPath];
}
return cell;
*/
}
在我的代碼它不顯示第一個單元格後,剩餘的細胞作爲我想要的。請有人幫助我。
編輯: 這裏是我的整個類
編輯2:
這裏是什麼,我需要做一個說明..
你能顯示更多的代碼嗎?例如,' - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {'因爲它決定了要創建多少個單元格。 –
@BenB c我編輯過的帖子兄弟..謝謝你試圖幫我 – Darshana
如果條件失敗會發生什麼? 'if([self datePickerIsShown] &&(self.datePickerIndexPath.row == indexPath.row))' – abmussani