我有一个iOS应用程序,它利用RestKit 0.20.1从Restful Web服务中检索数据.我还应该添加应用程序使用CoreData.应用程序启动时,主屏幕是一个由默认搜索词填充的集合视图.标题中还有一个用作搜索栏的文本字段.
当用户使用搜索栏时,我无法清除以前加载的单元格.它只是加载新单元格并将之前的单元格向下推.这是适用的代码.
- (BOOL) textFieldShouldReturn:(UITextField *)textField {
//This sets up the NSDictionary for the Restkit postObject parameters
NSArray *objects =[NSArray arrayWithObjects:textField.text, nil];
NSArray *keys =[NSArray arrayWithObjects: @"query",nil];
NSDictionary *params = [NSDictionary dictionaryWithObjects:objects forKeys:keys];
self.search=params;
//This is the POST request to the server
[[RKObjectManager sharedManager] postObject:nil path:@"/rest/search?ip=255.255.255.0" parameters:search success:nil failure:nil];
//This is what I thought would clear out the old and replace with the new
[self.collectionView reloadData];
[textField resignFirstResponder];
return YES;
}
Run Code Online (Sandbox Code Playgroud)
我引用了这个问题如何删除所有项目并向UICollectionView添加新项目?并且[collectionView reloadData]是公认的答案.
我选择了 …
我在UIcollectionView中遇到了一系列问题,我认为解决问题的方法是解决问题.
好的,所以我有一个collectionview,可以从一个非常频繁更新的类加载对象,也许每隔几秒钟.
我遇到的第一个问题; 当我选择一个单元格并突出显示它时,集合视图下方的另一个单元格也会突出显示.我的解决方案是创建一个选定单元阵列并在新阵列中运行循环以决定要突出显示的内容.
现在,重新加载collectionview时会出现问题.单元格继续保持突出显示并显示为已选中,但它们没有注册触摸,因此我无法取消选择它.
- (NSInteger)collectionView:(UICollectionView *)view numberOfItemsInSection: (NSInteger)section
{
return [self.deviceList count];
}
- (NSInteger)numberOfSectionsInCollectionView: (UICollectionView *)collectionView
{
return 1;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
DeviceCollectionViewCell *cell = [self.deviceCollectionView dequeueReusableCellWithReuseIdentifier:@"DeviceCell" forIndexPath:indexPath];
if([self.deviceList count] > indexPath.row)
{
cell.device = [self.deviceList objectAtIndex:indexPath.row];
}
if ([[self.deviceCollectionView indexPathsForSelectedItems] containsObject:indexPath]) {
NSLog(@"does it ever?");
// cell.backgroundColor = [UIColor blueColor];
}
for (TDDeviceParser *device in self.selectedDevices)
{
if ([cell.device.deviceTextRecord.serialNumber isEqualToString:device.deviceTextRecord.serialNumber])
{
[cell setSelected:YES];
break;
}
else
{
[cell setSelected:NO];
}
} …Run Code Online (Sandbox Code Playgroud) 我有一个UITableViewCell扩展并在点击时添加标签.
逻辑:
我
cellForRowAtIndexPath在所选单元格中添加了一个标签,然后didSelectRow...重新加载了tableView.在heightForRow...选定的单元格中展开.希望你能得到这张照片.
在didSelectRow...我必须reloadData,而不是开始/结束更新.我想要做的是reloadData并让它动画.我可以这样做:
[UIView transitionWithView: tableView
duration: 0.40f
options: UIViewAnimationOptionTransitionCrossDissolve
animations: ^(void)
{
[self.tableView reloadData];
}
completion: nil
}];
Run Code Online (Sandbox Code Playgroud)
这就是正在改变的细胞的交叉溶解.我想要的是UITableViewRowAnimationTop,但显然在转换选项中是不可能的.有没有办法reloadData和使用UITableViewRowAnimationTop?
我有一个UITableView有两个部分(顶部和底部).当在顶部(第0部分)"检查"项目时,我将它们移动到底部(第1部分),反之亦然.除了动画,一切都很好.
我正在使用以下内容,但行动作缓慢 - 我在其他应用程序中看到了更好的结果.我希望从顶部开始的行能够干净地动画到底部...以及从底部开始的行,以便在选中或取消选中它们时干净地动画到顶部.
// set the guests arrival status and use animation
[guestList beginUpdates];
if (!guest.didArrive) {
[guest setDidArrive:YES];
[guestList reloadSections:sectionIndexSet withRowAnimation:UITableViewRowAnimationBottom];
} else {
[guest setDidArrive:NO];
[guestList reloadSections:sectionIndexSet withRowAnimation:UITableViewRowAnimationTop];
}
[guestList endUpdates];
[guestList reloadData];
Run Code Online (Sandbox Code Playgroud)
我该怎么编码才能获得流畅的动画?
编辑:
我发现了这个问题.应该用这种方式编写:
//NSIndexSet *sectionIndexSet = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, 1)];
// set the guests arrival status and use animation
[guestList beginUpdates];
if (!guest.didArrive) {
[guest setDidArrive:YES];
[guestList reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationBottom];
} else {
[guest setDidArrive:NO];
[guestList reloadSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation:UITableViewRowAnimationTop];
}
[guestList endUpdates];
[guestList reloadData];
Run Code Online (Sandbox Code Playgroud)
注意我注释掉的第一行.我原本忽略了这个.如您所见,我使用的是构造不良的NSIndexSet.
我遇到了问题[UICollectionView reloadData],在调用numberOfSectionsInCollectionView我指定的委托之前,它似乎已经停滞了很长一段时间.这是发生的事情:
应用程序以立即可见的UICollectionView开始,并numberOfSectionsInCollectionView在委托上调用,该委托返回空数组中的项目数(即0),并立即开始从Web服务下载数组的数据.下载完成后,数据被反序列化并添加到上面的数组中,然后reloadData在UICollectionView实例上调用.这是应用程序似乎停止做任何事情的地方,并在20-30秒(或有时长达一分钟)后,代表接到一个电话numberOfSectionsInCollectionView.收到此调用后,重新加载很快就会完成.
我相信reloadData在自己的线程中运行,但我尝试在一个单独的线程中启动它,以确保它不是我的任何代码阻止进程.什么可能reloadData在它看起来卡住时做?有没有之间的任何中介委托方法reloadData和numberOfSectionsInCollectionView我应该执行?我认为这是第一个在重新加载后调用的方法,就iOS开发人员而言.
如果有人能告诉我可能出错的地方,太棒了,但我也很感激有关如何调试这个的提示!
这很奇怪,我知道但是我的[UITableView reloadData]没有删除旧单元格,如下所示:

你点击+按钮后发生的混乱,回来后再次更改了值.加号按钮将navigationController推送到另一个控制器,在我回来后单击后退按钮并更改了值,这就是我所看到的.这怎么可能??我使用了一个自定义视图(来自UIView的子类),我创建了一个带有UILabel的UIStepper.以下是自定义UIView的代码,controller.m和.h-.m文件.
Controller.m或者
@interface ViewController ()
@property NSString *docsDir;
@property sqlite3 *DB;
@property NSArray *dirPaths;
@property NSString* databasePath;
@property (strong, nonatomic) IBOutlet UITableView *tableView;
@property BOOL isCreatedBefore;
@property NSArray *theList;
@end
@implementation ViewController
@synthesize docsDir;
@synthesize DB;
@synthesize dirPaths;
@synthesize databasePath;
- (void)viewDidLoad
{
[super viewDidLoad];
dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
docsDir = [dirPaths objectAtIndex:0];
databasePath = [[NSString alloc] initWithString: [docsDir stringByAppendingPathComponent: [NSString stringWithFormat:@"database.db"]]];
[self createDatabase];
self.theList = [self readAllEntries];
}
-(void) viewWillAppear:(BOOL)animated{
self.theList = …Run Code Online (Sandbox Code Playgroud) 您好:我在我的应用程序中使用了一个集合视图,我注意到它需要比预期更长的刷新时间reloadData.我的集合视图有1个section,我用5 cell秒测试它(每个都有2个按钮和一个标签).我将一些日志放入我的代码中,以显示系统实际需要刷新多长时间.有趣的是,日志表明它的刷新速度比它快.例如,在设备上,它将花费约0.2秒(明显),但这里是日志:
0.007s从reloadData调用的时间到第一次cellForItemAtIndexPath调用的时间
0.002s 每个单元要加载并返回
0.041s从reloadData调用时间到返回单元格#5的时间
cellForItemAtIndexPath函数中没有任何特别密集的东西(基本上只是NSArray在indexPaths中找到一个包含3个值的字典row).即使我删除了这个并且只返回一个带有空白按钮的单元格,我也看到了相同的行为.
有没有人知道为什么会发生这种情况?顺便提一下,它只发生在物理设备(iPad Air)上.谢谢!
编辑#1
根据Per @ brian-nickel的评论,我使用了Time Profiler工具,并发现每次reloadData调用确实都会出现峰值.这是一个截图:

@ArtSabintsev,这是围绕reloadData调用的函数,后跟cellForItemAtIndexPath:
//Arrays were just reset, load new data into them
//Loop through each team
for (NSString *team in moveUnitsView.teamsDisplaying) { //CURRENT TEAM WILL COME FIRST
//Create an array for this team
NSMutableArray *teamArr = [NSMutableArray new];
//Loop through all …Run Code Online (Sandbox Code Playgroud) objective-c reloaddata ios uicollectionview uicollectionviewcell
来自apple doc 修改获取请求我看到可以更改NSFetchRequestfor NSFetchedResultsController.步骤很容易设置.
调用后performFetch:我觉得有必要调用reloadData表视图.如何进行这样的通话?
阅读一些stackoverflow主题,我已经看到调用该方法在大多数情况下应该工作.但有没有正确的方法呢?
在如何以编程方式切换UITableView的NSFetchedResultsController(或其谓词)?,TechZen写道:
只需确保在交换控制器之前将tableview本身发送为beginUpdates,然后在完成后再发送endUpdates.这可以防止表在换出FRC时在窄窗口中询问数据.然后调用reloadData.
你能解释一下这究竟是什么意思吗?
uitableview nsfetchedresultscontroller nsfetchrequest reloaddata ios
这对你们所有人来说都是挑战......
我有一个UICollectionView内部我的UIViewController女巫正确加载.我也有一个定制UICollectionViewCell类女巫包含一个UIButton.
我NSArray从我的服务器检索一些UIImage对象,以便将一个背景图像分配给我的自定义按钮UICollectionViewCell.
这是我的cellForItemAtIndexPath功能代码:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath;
{
UserPhotoCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"userPhotoCell" forIndexPath:indexPath];
if (indexPath.section == 0) {
[[cell imageButton] setBackgroundImage:[userPublicImages objectAtIndex:indexPath.row] forState:UIControlStateNormal];
} else {
[[cell imageButton] setBackgroundImage:[userPrivateImages objectAtIndex:indexPath.row] forState:UIControlStateNormal];
}
return cell;
}
Run Code Online (Sandbox Code Playgroud)
你可以看到很简单.
这有一个奇怪的行为:如果我把我的所有习惯都UICollectionViewCell放在其中的一个部分UICollectionView,那么性能还可以......
有任何想法吗?
一些额外的信息:UICollectionView有标题.自定义标题.这只是一个UIView机智UILabel.
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
UICollectionReusableView *reusableView …Run Code Online (Sandbox Code Playgroud) 我试图从tableview重新加载一个特定的行,但在重新加载后,tableview的contentOffset被重置为(0,0).我试图添加[tableview beginUpdates]和重新加载[tableview endUpdates]reloadRowsAtIndexPaths,但没有改变行为.
问题在这里被问到调用reloadRowsAtIndexPaths删除tableView contentOffset但它没有解决问题.我很确定动画与此行为无关.我还不确定如何在重新加载tableview行的同时保持tableview的内容Offset.
[tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
ios ×10
reloaddata ×10
uitableview ×5
objective-c ×3
arrays ×1
core-data ×1
restkit-0.20 ×1
touch ×1
xcode ×1