numOfRows方法的問題,這是我的UITableViewDateSource代碼:一些的UITableView
#import "TableViewDataSource.h"
@implementation TableViewDataSource
@synthesize tableView;
@synthesize tableCell;
@synthesize LHfetchedResultsController;
@synthesize numberOfRows;
@synthesize dataTemp;
@synthesize paused;
-(id)initWithTableView:(UITableView *) tableView
{
self = [super init];
if (self) {
self.tableView = tableView;
self.tableView.dataSource = self;
self.tableView.delegate = self;
}
return self;
}
-(void)dateSourceWithChineseNewestVideosFetchedResultsController
{
self.tableCell = [TableCellModel getCellOfFreeChampionsList];
[self setChineseNewestVideosLHFetchedResultsController];
}
-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
[self configCellData:indexPath cell:self.tableCell];
// Configure the cell with data from the managed object.
return self.tableCell;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if ([[self.LHfetchedResultsController sections] count] > 0) {
id <NSFetchedResultsSectionInfo> sectionInfo = [[self.LHfetchedResultsController sections] objectAtIndex:section];
self.numberOfRows = [sectionInfo numberOfObjects];
// return self.numberOfRows;
return 1;
} else
return 0;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [[self.LHfetchedResultsController sections] count];
}
-(void)configCellData:(NSIndexPath *)indexPath cell:(id)cell
{
NSLog(@"DataSourceTempCount is %lu",(unsigned long)self.dataTemp.count);
// NSInteger indexNum = indexPath.row;
// ChineseNewestVideos * Video = [self.dataTemp objectAtIndex:indexNum];
ChineseNewestVideos * Video = [self.LHfetchedResultsController objectAtIndexPath:indexPath];
UITextView * textView = [self.tableCell viewWithTag:11];
textView.text = Video.title;
UILabel * la = [self.tableCell viewWithTag:12];
la.text = [NSString stringWithFormat:@"Data Count is %lu",(unsigned long)self.numberOfRows];
if (indexPath.row %2 == 0) {
self.tableCell.backgroundColor = [UIColor greenColor];
}else
{
self.tableCell.backgroundColor = [UIColor brownColor];
}
}
-(void)setLHFetchedResultsController:(NSFetchedResultsController *)fetchedResultsController
{
self.LHfetchedResultsController = fetchedResultsController;
self.LHfetchedResultsController.delegate = self;
NSError * err;
if (![self.LHfetchedResultsController performFetch:&err]) {
//啓動
NSLog(@"Unresolved error : %@, %@",err,[err userInfo]);
exit(-1);
}
}
-(void)setChineseNewestVideosLHFetchedResultsController
{
NSManagedObjectContext * context = ((AppDelegate*)[[UIApplication sharedApplication] delegate]).persistentContainer.viewContext;
NSFetchRequest * request = [ChineseNewestVideos fetchRequest];
NSEntityDescription * testEntity = [NSEntityDescription entityForName:@"ChineseNewestVideos" inManagedObjectContext:context];
request.entity = testEntity;
NSSortDescriptor * sort = [[NSSortDescriptor alloc] initWithKey:@"createdate" ascending:NO];
[request setSortDescriptors:[NSArray arrayWithObject:sort]];
// [request setFetchBatchSize:20];
NSFetchedResultsController * ChineseNewestVideosLHFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:request managedObjectContext:context sectionNameKeyPath:nil cacheName:nil];
[self setLHFetchedResultsController:ChineseNewestVideosLHFetchedResultsController];
}
的TableView是視圖控制器的屬性 數據沒有問題,但表顯示已經問題 從-(void)setChineseNewestVideosLHFetchedResultsController
時啓動我設置了不同的退貨-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
,顯示不同 這樣:
當退貨時1 when return one
時返回2 when return two
時返回3 [當返回3] [3]
時返回4個或更多 [當返回四個或更多] [4]
顯示總是像這樣,當我放棄時,textview將突然消失 誰知道發生了什麼?
[鏈接]這個方法:https://i.stack.imgur.com/3VqcY.png [鏈接]:https://i.stack.imgur.com/QQz7a。 png –
這裏是當我改變回到3或4或更多 –
爲什麼沒有細胞出隊? – Larme