我正在使用一個自定義單元格用於我的UITableview,其中有幾個UILabels。在一個標籤中,我將它的顏色設置爲紅色,這對我來說工作得很好。但只要我通過Egorefresh Table委託方法重載TableView方法,其他單元格的標籤顏色也開始變爲紅色。我不知道爲什麼會出現這個問題,它給我造成了很多的厭惡。自定義單元格在同一Tableview中複製另一個單元格的屬性
這是TableView中的數據源的方法的cellForRowAtIndexPath的代碼:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell
forRowAtIndexPath:(NSIndexPath *)indexPath{
// Set the Frame for BackgroundView of Cell.
NSDictionary * insuranceDic = [arr_insurance objectAtIndex:indexPath.row];
insuranceDic = [[AppDelegate sharedInstance] removeNullsFromDictonary:insuranceDic];
InsuranceCell * mycell = (InsuranceCell *)cell;
if([[insuranceDic valueForKey:@"active"] isEqualToString:@"N"]){
//TTTRegexAttributedLabel * label = [[TTTRegexAttributedLabel alloc] init];
mycell.lbl_insuranceName.text = [NSString stringWithFormat:@"%@ (%@)",
[insuranceDic valueForKey:@"insurance_name"],@"Inactive"];
mycell.lbl_insuranceName.textColor = [UIColor redColor];
//[label setText:cell.lbl_insuranceName.text withRegex:@"(Inactive)" withFont:
[UIFont boldSystemFontOfSize:12] withColor:[UIColor redColor]];
}
else{
mycell.lbl_insuranceName.text = [insuranceDic valueForKey:@"insurance_name"];
}
}
以及從這些方法重新加載表鑑於上述問題是發生:
#pragma mark -
#pragma mark UIScrollViewDelegate Methods
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
// For Top Pull to refresh.
[_refreshHeaderView egoRefreshScrollViewDidScroll:scrollView];
//For Bottom Pull to refresh.
[pullToBottomRefreshManager_ tableViewScrolled];
}
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:
(BOOL)decelerate{
// For Top Pull to refresh.
[_refreshHeaderView egoRefreshScrollViewDidEndDragging:scrollView];
//For Bottom Pull to refresh.
[pullToBottomRefreshManager_ tableViewReleased];
}
#pragma mark -
#pragma mark EGORefreshTableHeaderDelegate Methods
// Belowline is for stop refresh indicator
//[_refreshHeaderView
egoRefreshScrollViewDataSourceDidFinishedLoading:self.tableView];
- (void)egoRefreshTableHeaderDidTriggerRefresh:(EGORefreshTableHeaderView*)view{
// When we going to refresh the data we need to reset the start varible to 1
// and also removeallthe previous objects from the array.
str_start = @"1";
[self getInsuranceList];
}
- (BOOL)egoRefreshTableHeaderDataSourceIsLoading:(EGORefreshTableHeaderView*)view{
return isReloading; // should return if data source model is reloading
}
- (NSDate*)egoRefreshTableHeaderDataSourceLastUpdated:
(EGORefreshTableHeaderView*)view{
return [NSDate date]; // should return date data source was last changed
}
#pragma mark -
#pragma mark MNMBottomPullToRefreshManagerClient Methods
- (void)bottomPullToRefreshTriggered:(MNMBottomPullToRefreshManager *)manager {
// Here we are incrementing start with records per page means start+=recordsperpare
or start+=20.
str_start = [NSString stringWithFormat:@"%d",[str_start intValue]+
[str_recordsPerPage intValue]];
[self getInsuranceList];
}
這是的cellForRowAtIndexPath方法的代碼:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:
(NSIndexPath
*)indexPath{
static NSString *CellIdentifier = @"Cell";
InsuranceCell * cell = [InsuranceCell dequeOrCreateInTable:tableView];
// UITableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[InsuranceCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier] autorelease];
}
NSDictionary * insuranceDic = [arr_insurance objectAtIndex:indexPath.row];
insuranceDic = [[AppDelegate sharedInstance] removeNullsFromDictonary:insuranceDic];
cell.lbl_insuranceNo.text = [insuranceDic valueForKey:@"insurance_no"];
cell.lbl_groupNo.text = [insuranceDic valueForKey:@"group_no"];
cell.lbl_priority.text = [self getPriorityDescFromCode:[insuranceDic
valueForKey:@"priority"]];
cell.lbl_startDate.text = [insuranceDic valueForKey:@"start_date"];
cell.lbl_endDate.text = [insuranceDic valueForKey:@"end_date"];
cell.lbl_copay.text = [insuranceDic valueForKey:@"copay"];
// This Condition is For setting alternate (White/SkyBlue) Background color for cell.
// if (fmod(indexPath.row, 2)==0) {
// cell.backgroundView.backgroundColor = [UIColor colorFromRGBIntegers:237 green:243 blue:249 alpha:1];
//
// }
// else{
// cell.backgroundView.backgroundColor = [UIColor colorFromRGBIntegers:250 green:250 blue:250 alpha:1];
// }
cell.selectionStyle = UITableViewCellEditingStyleNone;
return cell;
}
其中是你的cellForRowAtIndexPath方法? – iPatel 2013-04-05 12:48:24
代碼首先在cellForRowAtIndexPath方法中完成,但同樣的錯誤出現在那裏。所以我在willDisplayCell中編碼,並錯誤地將它命名爲cellForRowAtIndexPath。所以請爲上面的代碼建議一些東西? – Shikhar 2013-04-05 12:53:31